home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / Persist / tiButtonPanel.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-01-07  |  82.8 KB  |  2,824 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   TechInsite Pty. Ltd.
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: info@techinsite.com.au
  8.  
  9.   Notes:
  10.  
  11. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  12. unit tiButtonPanel;
  13.  
  14. interface
  15.  
  16. uses
  17.   Windows, SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
  18.   Controls, Forms, Dialogs, StdCtrls, mask, buttons, extCtrls,
  19.   gauges, printers, fileCtrl, db, dbTables, grids, DBGrids, comctrls,
  20.   spin, registry, ImgList
  21.   ,math // min
  22.   ;
  23.  
  24. const
  25.   cValidFloatChrs: set of char = [ '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ] ;
  26.  
  27. type
  28.  
  29.   // A TCustomPanel with the border set to none, and the caption turned off.
  30.   // This control is not registered with the component pallet, as it
  31.   // is intended for use as the starting point for composite controls.
  32.   //----------------------------------------------------------------------------
  33.   TtiPanel = class( TCustomPanel )
  34.   public
  35.     Constructor Create( owner : TComponent ) ; override ;
  36.   end ;
  37.  
  38.  
  39.   // TtiStaticPickList:  Lists with items hard-coded into the program
  40.   //----------------------------------------------------------------------------
  41.   TtiStaticPickList = class( TCustomComboBox )
  42.   private
  43.     procedure   setText( sValue : string ) ;
  44.     function    getText : string ;
  45.   protected
  46.     procedure   Loaded ; override ;
  47.     procedure   ReadItems ; virtual ; abstract ;
  48.   published
  49.     property    Text : string read getText write setText ;
  50.     property    Top ;
  51.     property    Left ;
  52.     property    Height ;
  53.     property    Width  ;
  54.     property    Visible ;
  55.     property    Enabled ;
  56.     property    OnExit ;
  57.     property    OnChange ;
  58.     property    ShowHint ;
  59.   public
  60.     constructor create( owner : TComponent ) ; override ;
  61.   end;
  62.  
  63.   //----------------------------------------------------------------------------
  64.   RangeException = class( Exception ) ;
  65.   TFloatValidateEvent = procedure( Sender: TWinControl ; var rValue : real) of object;
  66.   TBaseFloatEdit   = class( TCustomEdit )
  67.   private
  68.     FsEditMask : string ;
  69.     FbApplyMask : boolean ;
  70.     FiPrecision : integer ;
  71.     FOnValidate : TFloatValidateEvent ;
  72.     FsTextBefore : string ;
  73.     FsTextAfter  : string ;
  74.     FrMinValue   : real ;
  75.     FrMaxValue   : real ;
  76.     FsBeforeApplyKey : string ;
  77.  
  78.     function  getAsString : string ;
  79.     procedure setAsString( sValue: string);
  80.     procedure setAsFloat( rValue : real ) ;
  81.     function  getAsFloat : real ;
  82.     procedure BaseFloatEditClick( sender : TObject ) ;
  83.     procedure enterBaseFloatEdit( sender : TObject ) ;
  84.     procedure exitBaseFloatEdit( sender : TObject ) ;
  85.     procedure baseFloatKeyPress( Sender: TObject; var Key: Char );
  86.     procedure baseFloatOnChange( sender : TObject ) ;
  87.     function  removeFormatChr( sValue : string ) : string ;
  88.     procedure setPrecision( iValue : integer ) ;
  89.     function  isValidFloat( sValue : string ) : boolean ;
  90.     procedure refresh ;
  91.     procedure setTextAfter( sValue : string ) ;
  92.     procedure setTextBefore( sValue : string ) ;
  93.     procedure setMinValue( rValue : real ) ;
  94.     procedure setMaxValue( rValue : real ) ;
  95.     procedure setApplyMask( bValue : boolean ) ;
  96.     function  withinMinMaxLimits( value : real ) : boolean;
  97.     function  customStrToFloat(var pStrValue: string): real;
  98.   protected
  99.     property    TextBefore : string read FsTextBefore write setTextBefore ;
  100.     property    TextAfter  : string read FsTextAfter  write setTextAfter ;
  101.     property    AsString  : string read getAsString write setAsString ;
  102.     property    AsFloat   : real   read getAsFloat  write setAsFloat  ;
  103.     property    Precision : integer read FiPrecision write setPrecision ;
  104.     property    MinValue  : real    read FrMinValue write setMinValue ;
  105.     property    MaxValue  : real    read FrMaxValue write setMaxValue ;
  106.   published
  107.     // property    OnChange ;
  108.     property    OnValidate : TFloatValidateEvent read FOnValidate write FOnValidate ;
  109.     // Don't publish this, as it is used internally. Use OnValidate instead.
  110.     // property    OnExit ;
  111.     property    Font ;
  112.     property    TabOrder ;
  113.     property    ApplyMask : boolean read FbApplyMask write setApplyMask ;
  114. //    property    MaxLength ;
  115.   public
  116.     constructor create( owner : TComponent ) ; override ;
  117.   end ;
  118.  
  119.   // TtiDBGrid
  120.   //------------------------------------------------------------------------------
  121.   TTextOrBitmap = ( tobTextOnly, tobBitmapOnly, tobBoth ) ;
  122.  
  123.   TCalcCellDispPropsEvent = procedure( Sender: TObject ; dataSet : TDataSet ;
  124.                                        sFieldName : string ;
  125.                                        var colorFont, colorCell : TColor ) of object;
  126.   TCalcCellBitMapEvent    = procedure( Sender: TObject ; dataSet : TDataSet ;
  127.                                        sFieldName : string ;
  128.                                        bitMap : TBitMap ;
  129.                                        var textOrBitmap : TTextOrBitmap ) of object;
  130.  
  131.   TtiDBGrid = class( TCustomDBGrid )
  132.   private
  133.     FBitmap    : TBitmap ;
  134.     FOnCalcCellDispProps : TCalcCellDispPropsEvent ;
  135.     FOnCalcCellBitMap    : TCalcCellBitMapEvent ;
  136.  
  137.     procedure customDrawCell(Sender: TObject; const Rect: TRect;
  138.                              DataCol: Integer; Column: TColumn; State: TGridDrawState); virtual ;
  139.     procedure drawBitmapInCell(const Rect: TRect; DataCol: Integer;
  140.                                     Column: TColumn; State: TGridDrawState ;
  141.                                     textOrBitmap : TTextOrBitmap );
  142.   protected
  143.   published
  144.     property Align;
  145.     property Anchors;
  146.     property BorderStyle;
  147.     property Ctl3D;
  148.     property Color;
  149.     property Columns stored False; //StoreColumns;
  150.     property Constraints;
  151.     property DataSource;
  152.     property Enabled;
  153.     property FixedColor;
  154.     property Font;
  155.     property Options;
  156.     property PopupMenu;
  157.     property ReadOnly;
  158.     property ShowHint;
  159.     property SelectedRows ;
  160.     property TabOrder;
  161.     property TabStop;
  162.     property TitleFont;
  163.     property Visible;
  164.     property OnDblClick;
  165.     property OnKeyPress;
  166.     property OnTitleClick;
  167.     property OnCalcCellDispProps : TCalcCellDispPropsEvent read FOnCalcCellDispProps write FOnCalcCellDispProps ;
  168.     property OnCalcCellBitmap     : TCalcCellBitMapEvent read FOnCalcCellBitMap write FOnCalcCellBitMap ;
  169.     property OnEnter ;
  170.     property OnExit  ;
  171.  
  172. //    property BiDiMode;
  173. //    property DefaultDrawing;
  174. //    property DragCursor;
  175. //    property DragKind;
  176. //    property DragMode;
  177. //    property ImeMode;
  178. //    property ImeName;
  179. //    property ParentBiDiMode;
  180. //    property ParentColor;
  181. //    property ParentCtl3D;
  182. //    property ParentFont;
  183. //    property ParentShowHint;
  184. //    property OnCellClick;
  185. //    property OnColEnter;
  186. //    property OnColExit;
  187. //    property OnColumnMoved;
  188. //    property OnDrawColumnCell;
  189. //    property OnDrawDataCell;  // obsolete
  190. //    property OnDragDrop;
  191. //    property OnDragOver;
  192. //    property OnEditButtonClick;
  193. //    property OnEndDock;
  194. //    property OnEndDrag;
  195. //    property OnEnter;
  196. //    property OnExit;
  197. //    property OnKeyDown;
  198. //    property OnKeyUp;
  199. //    property OnStartDock;
  200. //    property OnStartDrag;
  201.   public
  202.     constructor create( owner : TComponent ) ; override ;
  203.     destructor  destroy ; override ;
  204.     property  canvas ;
  205.   end ;
  206.  
  207. // TPickList:  Dynamic pick lists. Lists with items looked up at runtime   TPickList = class( TCustomPanel )
  208. //------------------------------------------------------------------------------
  209.   TtiPickList = class( TCustomPanel )
  210.   private
  211.     oEdit        : TEdit ;
  212.     oSpeedButton : TSpeedButton ;
  213.     oTable       : TTable       ;
  214.     oDataSource  : TDataSource  ;
  215.     oForm        : TForm        ;
  216.     oDBGrid      : TDBGrid      ;
  217.     FsGridFieldNames    : string ;
  218.     FsGridDisplayLables : string ;
  219.     FsEditFieldNames    : string ;
  220.     FsReturnFieldName   : string ;
  221.     FsRange             : string ;
  222.  
  223.     FsSearchText        : string       ;
  224.  
  225.     FOnChange           : TNotifyEvent ;
  226.  
  227.     procedure WMSize( var Message: TWMSize ) ; message WM_SIZE ;
  228.     procedure speedButtonClick( sender : TObject ) ;
  229.     procedure oFormDeactivate(  Sender: TObject )  ;
  230.     procedure DBGridKeyPress(   Sender: TObject ; var Key : Char );
  231.     procedure DBGridDblClick(   Sender: TObject ) ;
  232.     procedure EditKeyPress(     Sender: TObject ; var Key : Char );
  233.     procedure EditKeyDown(      Sender: TObject ; var Key : word ;Shift: TShiftState );
  234.  
  235.     procedure copyTextToEdit ;
  236.  
  237.     procedure openTable ;
  238.     procedure setTableName( sValue : string ) ;
  239.     function  getTableName : string ;
  240.     procedure setIndexName( sValue : string ) ;
  241.     function  getIndexName : string ;
  242.     function  getText : string ;
  243.     procedure setText( sValue : string ) ;
  244.     procedure setSearchText( sValue : string ) ;
  245.     property  searchText : string read FsSearchText write setSearchText ;
  246.     procedure setRange( sValue : string ) ;
  247.  
  248.   protected
  249.     property    tableName : string read getTableName write setTableName                       ;
  250.     property    indexName : string read getIndexName write setIndexName                       ;
  251.     property    gridFieldNames    : string read FsGridFieldNames write FsGridFieldNames       ;
  252.     property    gridDisplayLables : string read FsGridDisplayLables write FsGridDisplayLables ;
  253.     property    editFieldNames    : string read FsEditFieldNames    write FsEditFieldNames    ;
  254.     property    ReturnField       : string read FsReturnFieldName   write FsReturnFieldName   ;
  255.     property    range             : string read FsRange             write setRange            ;
  256.   public
  257.  
  258.   published
  259.     constructor create( oOwner : TComponent ) ; override ;
  260.     destructor  free ;
  261.     property    Top  ;
  262.     property    Left ;
  263.     property    Width ;
  264.     property    Height ;
  265.     property    visible ;
  266.     property    enabled ;
  267.     property    OnExit ;
  268.     property    OnChange: TNotifyEvent read FOnChange write FOnChange;
  269.     property    text : string read getText write setText ;
  270.   end;
  271.  
  272.   // TAbort: Abort dialog box.
  273.   //----------------------------------------------------------------------------
  274.   TtiAbort = class(TComponent)
  275.   private
  276.     oForm : TForm ;
  277.     oGauge : TGauge ;
  278.     oBitBtnAbort : TBitBtn ;
  279.     bAbort : boolean ;
  280.     procedure bitBtnAbortClick( sender : TObject ) ;
  281.     procedure pPutMaxValue( iMaxValue : longInt ) ;
  282.     function  pGetMaxValue : longInt ;
  283.     procedure pPutProgress( iProgress : longInt ) ;
  284.     function  pGetProgress : longInt ;
  285.   published
  286.     constructor create( oOwner : TComponent ) ; override ;
  287.     destructor  destroy ; override ;
  288.     property    abort    : boolean read bAbort write bAbort ;
  289.     property    maxValue : longInt read pGetMaxValue write pPutMaxValue ;
  290.     property    progress : longInt read pGetProgress write pPutProgress ;
  291.     function    IncGauge : boolean ;
  292.     function    Inc : boolean ;
  293.     procedure   show( sCaption : string ; iMaxValue : longInt ) ;
  294.     procedure   hide ;
  295.   end;
  296.  
  297. //  TPickPrinter
  298. //------------------------------------------------------------------------------
  299.   TtiPickPrinter = class( TtiStaticPickList )
  300.   public
  301.     procedure readItems ; override ;
  302.   end ;
  303.  
  304. // TCustomPicker
  305. //------------------------------------------------------------------------------
  306.   TtiCustomPicker = class( TCustomPanel )
  307.   private
  308.     oEdit   : TEdit ;
  309.     oSpeedButton : TSpeedButton ;
  310.     FOnChange : TNotifyEvent ;
  311.     procedure WMSize( var Message: TWMSize ) ; message WM_SIZE ;
  312.     procedure buttonClick( sender : TObject ) ; virtual ;
  313.     procedure setText( sValue : string ) ; virtual ;
  314.     function  getText : string ; virtual ;
  315.     procedure editChange( sender : TObject ) ;
  316.   protected
  317.     property onClick ;
  318.   public
  319.     constructor create( owner : TComponent ) ; override ;
  320.   published
  321.     property Anchors ;
  322.     property text : string read getText write setText ;
  323.     property font ;
  324.     //property onExit ;
  325.     property onChange : TNotifyEvent read FOnChange write FOnChange ;
  326.   end ;
  327.  
  328. // TPickDirectory
  329. //------------------------------------------------------------------------------
  330.   TtiPickDirectory = class( TtiCustomPicker )
  331.   private
  332.     FbMustExist : boolean ;
  333.     FbCreateDir: boolean;
  334.     procedure buttonClick( sender : TObject ) ; override ;
  335.     procedure pickDirectoryOnExit( sender : TObject ) ;
  336.   protected
  337.     procedure loaded ; override ;
  338.   published
  339.     property MustExist : boolean read FbMustExist write FbMustExist ;
  340.     property CreateDir : boolean read FbCreateDir write FbCreateDir default false ;
  341.   public
  342.     constructor create( owner : TComponent ) ; override ;
  343.   end ;
  344.  
  345. // TPickFile
  346. //------------------------------------------------------------------------------
  347.   TtiPickFile = class( TtiCustomPicker )
  348.   private
  349.     FsDefaultExt : string ;
  350.     FsFilter     : string ;
  351.     FsTitle      : string ;
  352.     procedure buttonClick( sender : TObject ) ; override ;
  353.   published
  354.     property onExit ;
  355.     property DefaultExt : string read FsDefaultExt write FsDefaultExt ;
  356.     property Filter     : string read FsFilter  write FsFilter ;
  357.     property Title      : string   read FsTitle    write FsTitle ;
  358.     property Visible ;
  359.   public
  360.     constructor create( owner : TComponent); override ;
  361.   end ;
  362.  
  363.  
  364. // TAmuseUser
  365. //------------------------------------------------------------------------------
  366.  TtiAmuseUser = class(TComponent)
  367.   private
  368.     oForm : TForm ;
  369.     oGauge : TGauge ;
  370.     oLabel : TLabel ;
  371.     oTimer : TTimer ;
  372.     function  getCaption : string ;
  373.     procedure setCaption( sValue : string ) ;
  374.     function  getMessageLine : string ;
  375.     procedure setMessageLine( sValue : string ) ;
  376.     procedure oTimerTimer( sender: TObject ) ;
  377.     procedure setEnabled( bValue : boolean ) ;
  378.     function  getEnabled : boolean ;
  379.   published
  380.     constructor create( oOwner : TComponent ) ; override ;
  381.     destructor  free ;
  382.     property    enabled : boolean read getEnabled write setEnabled ;
  383.     property    caption       : string read getCaption write setCaption ;
  384.     property    messageLine   : string read getMessageLine   write setMessageLine ;
  385.   end ;
  386.  
  387. // THistoryComboBox
  388. //------------------------------------------------------------------------------
  389.   TtiHistoryComboBox = class(TCustomComboBox)
  390.   private
  391.     FOnValidate : TNotifyEvent ;
  392.     FiHistoryCount: integer;
  393.     oReg : TRegINIFile ;
  394.     procedure historyComboBoxExit(sender: TObject);
  395.     procedure SetHistoryCount(const iValue: integer);
  396.   protected
  397.     procedure loaded ; override ;
  398.   published
  399.     property Anchors ;
  400.     property Color ;
  401.     property Font ;
  402.     property Enabled ;
  403.     property ShowHint ;
  404.     property MaxLength ;
  405.     property Text ;
  406.     property TabOrder ;
  407.     property HistoryCount : integer read FiHistoryCount write setHistoryCount ;
  408.     property onValidate : TNotifyEvent read FOnValidate write FOnValidate ;
  409.     property onChange ;
  410.   public
  411.     constructor create(owner: TComponent);override;
  412.     destructor  destroy ; override ;
  413.   end ;
  414.  
  415.   //----------------------------------------------------------------------------
  416.   TtiFloatEdit   = class( TBaseFloatEdit )
  417.   private
  418.   protected
  419.   published
  420.     property AsString ;
  421.     property AsFloat  ;
  422.     property Precision ;
  423.     property MinValue ;
  424.     property MaxValue ;
  425.   public
  426.     constructor create( owner : TComponent ) ; override ;
  427.   end ;
  428.  
  429.   //----------------------------------------------------------------------------
  430.   TtiCurrencyEdit = class( TBaseFloatEdit )
  431.   private
  432.   protected
  433.   published
  434.     property AsString ;
  435.     property AsFloat  ;
  436.     property Precision ;
  437.     property MinValue ;
  438.     property MaxValue ;
  439.   public
  440.     constructor create( owner : TComponent ) ; override ;
  441.   end ;
  442.  
  443.   //----------------------------------------------------------------------------
  444.   TtiPercentEdit = class( TBaseFloatEdit )
  445.   private
  446.   protected
  447.   published
  448.     property AsString ;
  449.     property AsFloat  ;
  450.     property Precision ;
  451.     property MinValue ;
  452.     property MaxValue ;
  453.   public
  454.     constructor create( owner : TComponent ) ; override ;
  455.   end ;
  456.  
  457.   //----------------------------------------------------------------------------
  458.   TtiIntegerEdit = class( TBaseFloatEdit )
  459.   private
  460.     function getAsInteger : longInt ;
  461.     procedure setAsInteger( iValue : longInt ) ;
  462.   protected
  463.   published
  464.     property AsString ;
  465.     property AsInteger : longInt read getAsInteger write setAsInteger ;
  466.     property MinValue ;
  467.     property MaxValue ;
  468.   public
  469.     constructor create( owner : TComponent ) ; override ;
  470.   end ;
  471.  
  472.   //----------------------------------------------------------------------------
  473.   TtiDateEdit     = class( TDateTimePicker )
  474.   private
  475.     FsDate : string ;
  476.   protected
  477.   published
  478.     property DateAsString : string read FsDate ;
  479.   public
  480.   end ;
  481.  
  482.   //----------------------------------------------------------------------------
  483.   TtiToolBar = class( TToolBar )
  484.   private
  485.   protected
  486.   published
  487.   public
  488.     constructor create( owner : TComponent ) ; override ;
  489.   end ;
  490.  
  491.   // TtiPickAlias
  492.   //----------------------------------------------------------------------------
  493.   TtiPickAlias = class( TtiStaticPickList )
  494.   private
  495.   protected
  496.     procedure ReadItems ; override ;
  497.   published
  498.   public
  499.   end;
  500.  
  501.   // TDateRange
  502.   //----------------------------------------------------------------------------
  503.   TDateGroup  = ( dgAll, dgWeek, dgMonth, dgToday, dgCustom ) ;
  504.   TtiDateRange  = class( TCustomGroupBox )
  505.   private
  506.     labelFrom : TLabel ;
  507.     labelTo   : TLabel ;
  508.  
  509.     FDateTimePickerFrom : TDateTimePicker ;
  510.     FDateTimePickerTo   : TDateTimePicker ;
  511.  
  512.     radioButtonDatesAll     : TRadioButton ;
  513.     radioButtonDatesMonth   : TRadioButton ;
  514.     radioButtonDatesWeek    : TRadioButton ;
  515.     radioButtonDatesToday   : TRadioButton ;
  516.     radioButtonDatesCustom  : TRadioButton ;
  517.     dDateAllEarliest        : TDateTime    ;
  518.     dDateAllLatest          : TDateTime    ;
  519.     FDateGroup              : TDateGroup   ;
  520.  
  521.     FOnChange               : TNotifyEvent ;
  522.  
  523.     procedure RadioButtonDatesClick( sender: TObject) ;
  524.     function  getDateFrom : TDateTime                 ;
  525.     procedure putDateFrom( const dDate : TDateTime )        ;
  526.     function  getDateTo : TDateTime                   ;
  527.     procedure putDateTo( const dDate : TDateTime )          ;
  528.     procedure setDateGroup( const dgDateGroup : TDateGroup ) ;
  529.     function  getDateGroup : TDateGroup ;
  530.     procedure OnChangeEvent( sender : TObject ) ;
  531.  
  532.   protected
  533.     procedure Loaded; override ;
  534.  
  535.   published
  536.     constructor create( oOwner : TComponent ) ; override ;
  537.     property dateAllEarliest  : TDateTime read dDateAllEarliest write dDateAllEarliest ;
  538.     property dateAllLatest    : TDateTime read dDateAllLatest   write dDateAllLatest   ;
  539.     property dateFrom         : TDateTime read getDateFrom      write putDateFrom        ;
  540.     property dateTo           : TDateTime read getDateTo        write putDateTo          ;
  541.     property dateGroup        : TDateGroup read getDateGroup      write setDateGroup default dgCustom ;
  542.     property top ;
  543.     property left ;
  544.     property OnChange : TNotifyEvent read FOnChange write FOnChange ;
  545.  
  546.   end;
  547.  
  548.  
  549. //  TOnDirectoryEvent = procedure( Sender: TWinControl ;
  550. //                                 var pDirectory : string ) of object;
  551.  
  552.   TtiClock = class( TtiPanel )
  553.   private
  554.     FTimer : TTimer ;
  555.     FLabel : TLabel ;
  556.     FsTimeFormat: string;
  557.     FiOffset : integer ;
  558.     procedure SetTimeFormat(const Value: string);
  559.   protected
  560.     procedure OnTimer( sender : TObject ) ; virtual ;
  561.     function  GetEnabled: boolean; override ;
  562.     procedure SetEnabled( Value: boolean); override ;
  563.   published
  564.     property Enabled    : boolean read GetEnabled   write SetEnabled ;
  565.     property TimeFormat : string  read FsTimeFormat write SetTimeFormat ;
  566.     property Offset     : integer read FiOffset     write FiOffset ;
  567.     property Font ;
  568.     property Color ;
  569.   public
  570.     Constructor Create( owner : TComponent ) ; override ;
  571.   end ;
  572.  
  573.   TtiButtonPanel = class( TCustomPanel )
  574.   private
  575.     FOnBtn2Click: TNotifyEvent;
  576.     FOnBtn1Click: TNotifyEvent;
  577.     FBtn1 : TBitBtn ;
  578.     FBtn2 : TBitBtn ;
  579.     procedure SetOnBtn1Click(const Value: TNotifyEvent);
  580.     procedure SetOnBtn2Click(const Value: TNotifyEvent);
  581.   protected
  582.     procedure DoBtn1Click( sender : TObject ) ; virtual ;
  583.     procedure DoBtn2Click( sender : TObject ) ; virtual ;
  584.   published
  585.     property OnBtn1Click : TNotifyEvent read FOnBtn1Click write SetOnBtn1Click ;
  586.     property OnBtn2Click : TNotifyEvent read FOnBtn2Click write SetOnBtn2Click ;
  587.   public
  588.     Constructor Create( owner : TComponent ) ; override ;
  589.     Destructor  Destroy ; override ;
  590.   end ;
  591.  
  592.   TtiMessageDlg = class( TComponent )
  593.   private
  594.     FForm : TForm ;
  595.     FBtns : TList ;
  596.     FMemo : TMemo ;
  597.     FsResult : string ;
  598.     Procedure Clear ;
  599.     Procedure DoOnClick( sender : TObject ) ;
  600.   public
  601.     Constructor Create( owner : TComponent ) ; override ;
  602.     Destructor  Destroy ; override ;
  603.     Function    Execute( const psMessage : string ;
  604.                          paOptions : array of string ;
  605.                          psCaption : string ) : string ;
  606.   end ;
  607.  
  608.  
  609. const
  610.   clPaleYellow = $00E8FFFE ;
  611.   clPaleBlue   = $00FFF1EA ;
  612.   clPaleNavy   = $00FFEAED ;
  613.   clPaleGreen  = $00B3FFB3 ;
  614.   clPalePink   = $008080FF ;
  615.   cDefaultDateString  = '01/01/1980' ;
  616.   cMinHeight          =  21 ;
  617.   cMinWidth           = 121 ;
  618.   cTimeFormat         = 'hh:mm:ss am/pm' ;
  619.   cFloatEditMask      = '#,##0'  ;
  620.   cMyComputer         = 'My computer' ;
  621.   csSubDirPlaceHolder = 'SubDirPlaceHolder' ;
  622.   cuStrDirectoryDelimiter = '\' ;
  623.  
  624.  
  625. function  tiNumToken( sString, sToken : string ) : integer ;
  626. function  tiToken( sString, sToken : string; iNum : integer ) : string ;
  627. function  tiStrTran( sStr, sDel, sIns : string ) : string ;
  628. function  tiRemoveExtension( sValue : string ) : string ;
  629.  
  630. implementation
  631.  
  632. const
  633.   cdtOneSecond     = 1/24/60/60 ;
  634.  
  635. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  636. //*
  637. //* TtiStaticPickList
  638. //*
  639. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  640. //------------------------------------------------------------------------------
  641. constructor TtiStaticPickList.create( owner : TComponent ) ;
  642. begin
  643.   inherited create( owner ) ;
  644.   self.style := csDropDownList ;
  645. end ;
  646.  
  647. //------------------------------------------------------------------------------
  648. function TtiStaticPickList.getText : string ;
  649. begin
  650. //  readItems ;
  651.   if self.itemIndex = - 1 then begin
  652.     result := '' ;
  653.   end else begin
  654.     result := self.items[ self.itemIndex ] ;
  655.   end ;
  656. end ;
  657.  
  658. //------------------------------------------------------------------------------
  659. procedure TtiStaticPickList.setText( sValue : string ) ;
  660. begin
  661. //  readItems ;
  662.   self.itemIndex := self.items.indexOf( sValue ) ;
  663. end ;
  664.  
  665. //------------------------------------------------------------------------------
  666. procedure TtiStaticPickList.Loaded ;
  667. begin
  668.   inherited ;
  669.   ReadItems ;
  670. //if self.items.count > 0 then begin
  671. //  exit ;
  672. //end ;
  673. end ;
  674.  
  675. {
  676. procedure TtiStaticPickList.readItems ;
  677. begin
  678.   if self.items.count > 0 then begin
  679.     exit ;
  680.   end ;
  681. end ;
  682. }
  683.  
  684. {
  685. //------------------------------------------------------------------------------
  686. procedure TtiStaticPickList.dropDown ;
  687. begin
  688.   self.readItems ;
  689. end ;
  690. }
  691.  
  692. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  693. //*
  694. //* TBaseFloatEdit
  695. //*
  696. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  697. //------------------------------------------------------------------------------
  698. constructor TBaseFloatEdit.create( owner : TComponent ) ;
  699. begin
  700.   inherited create( owner ) ;
  701.   onEnter      := enterBaseFloatEdit ;
  702.   onExit       := exitBaseFloatEdit ;
  703.   onKeyPress   := baseFloatKeyPress ;
  704.   onChange     := baseFloatOnChange ;
  705.   onClick      := baseFloatEditClick ;
  706.   
  707.   self.width   := 57 ;
  708.   FsEditMask   := cFloatEditMask ;
  709.   FsTextBefore := '' ;
  710.   FsTextAfter  := '' ;
  711.   FrMinValue   := 0 ;
  712.   FrMaxValue   := 0 ;
  713.   FbApplyMask  := true ;
  714.   FsBeforeApplyKey := '' ;
  715.   self.precision := 0 ;
  716.   self.asFloat := 0 ;
  717. end ;
  718.  
  719. //------------------------------------------------------------------------------
  720. procedure TBaseFloatEdit.setAsString( sValue : string ) ;
  721. begin
  722.   if sValue = '' then begin
  723.     self.asFloat := 0 ;
  724.     exit ;
  725.   end ;
  726.  
  727.   if not isValidFloat( sValue ) then begin
  728.     self.asFloat := 0 ;
  729.     exit ;
  730.   end ;
  731.  
  732.   self.text := sValue ;
  733.   self.refresh ;
  734.  
  735. end ;
  736.  
  737. //------------------------------------------------------------------------------
  738. function  TBaseFloatEdit.getAsString : string ;
  739. begin
  740.   result := self.text ;
  741. end ;
  742.  
  743. //------------------------------------------------------------------------------
  744. function TBaseFloatEdit.isValidFloat( sValue : string ) : boolean ;
  745. var rValue : real ;
  746. begin
  747.   try
  748.     rValue := strToFloat( self.removeFormatChr( sValue )) ;
  749.     if rValue < rValue + 1 then ; // To trick compiler warnings
  750.     result := true ;
  751.   except
  752.     result := false ;
  753.   end ;
  754. end ;
  755.  
  756. //------------------------------------------------------------------------------
  757. function TBaseFloatEdit.getAsFloat : real ;
  758. var lStr : string ;
  759. begin
  760.   lStr := self.text ;
  761.   result := self.customStrToFloat( lStr ) ;
  762. end ;
  763.  
  764. //------------------------------------------------------------------------------
  765. function TBaseFloatEdit.customStrToFloat( var pStrValue : string ) : real ;
  766. var lStrValue : string ;
  767. begin
  768.   lStrValue := self.removeFormatChr( pStrValue ) ;
  769.   if lStrValue = '' then begin
  770.     result := 0 ;
  771.     exit ; //==>
  772.   end ;
  773.  
  774.   try
  775.     result := strToFloat( lStrValue ) ;
  776.   except
  777.     result := 0 ;
  778.   end ;
  779. end ;
  780.  
  781. //------------------------------------------------------------------------------
  782. procedure TBaseFloatEdit.setAsFloat( rValue : real ) ;
  783. var sValue : string ;
  784.     sMinValue : string ;
  785.     sMaxValue : string ;
  786. begin
  787. //  try
  788.     sValue := FsTextBefore + formatFloat( FsEditMask, rValue ) + FsTextAfter ;
  789.     if not self.withinMinMaxLimits( rValue ) then begin
  790. {
  791.     if (( FrMinValue <> 0 ) and ( rValue < FrMinValue )) or
  792.        (( FrMaxValue <> 0 ) and ( rValue > FrMaxValue )) then begin
  793.       // What if one of our FsM??Values are 0 ?
  794.       // Require some code to handle these situations
  795. }
  796.       sMinValue := FsTextBefore + formatFloat( FsEditMask, FrMinValue ) + FsTextAfter ;
  797.       sMaxValue := FsTextBefore + formatFloat( FsEditMask, FrMaxValue ) + FsTextAfter ;
  798.       raise RangeException.create( 'The value you entered, ' + sValue +
  799.                                    ' is out of range.' + #13 +
  800.                                    'Please enter a value between ' +
  801.                                    sMinValue + ' and ' +
  802.                                    sMaxValue ) ;
  803.     end ;
  804.  
  805.     self.text := sValue ;
  806. //  except
  807. //    self.asFloat := 0 ;
  808. //  end ;
  809. end ;
  810.  
  811. //------------------------------------------------------------------------------
  812. function TBaseFloatEdit.withinMinMaxLimits( value : real ) : boolean ;
  813. begin
  814.   result := not ((( FrMinValue <> 0 ) and ( value < FrMinValue )) or
  815.                  (( FrMaxValue <> 0 ) and ( value > FrMaxValue ))) ;
  816.   // What if one of our FsM??Values are 0 ?
  817.   // Require some code to handle these situations
  818. end ;
  819.  
  820. //------------------------------------------------------------------------------
  821. procedure TBaseFloatEdit.setMinValue( rValue : real ) ;
  822. begin
  823.   if (FrMaxValue <> 0 ) and (rValue >= FrMaxValue) then rValue := 0 ;
  824.   FrMinValue := rValue ;
  825.   self.refresh ;
  826. end ;
  827.  
  828. //------------------------------------------------------------------------------
  829. procedure TBaseFloatEdit.setMaxValue( rValue : real ) ;
  830. begin
  831.   if (FrMinValue <> 0) and (rValue <= FrMinValue) then rValue := 0 ;
  832.   FrMaxValue := rValue ;
  833.   self.refresh ;
  834. end ;
  835.  
  836. //------------------------------------------------------------------------------
  837. procedure TBaseFloatEdit.enterBaseFloatEdit( sender : TObject ) ;
  838. begin
  839.   self.text := self.removeFormatChr( self.text ) ;
  840.   self.selectAll ;
  841. end ;
  842.  
  843. //------------------------------------------------------------------------------
  844. procedure TBaseFloatEdit.exitBaseFloatEdit( sender : TObject ) ;
  845. var rValue : real ;
  846. begin
  847.   try
  848.     self.refresh ;
  849.   except
  850.     on e : rangeException do begin
  851.       messageDlg( e.message, mtError,
  852.                   [mbOK], 0 ) ;
  853.       self.setFocus ;
  854.     end else begin
  855.       self.setFocus ;
  856.       raise ;
  857.     end ;
  858.   end ;
  859.   rValue := self.AsFloat ;
  860.   if assigned( onValidate ) then onValidate( self, rValue ) ;
  861.   if rValue <> self.asFloat then self.asFloat := rValue ;
  862. end ;
  863.  
  864. //------------------------------------------------------------------------------
  865. function TBaseFloatEdit.removeFormatChr( sValue : string ) : string ;
  866. var i : integer ;
  867. begin
  868.   result := '' ;
  869.   for i := 1 to length( sValue ) do begin
  870.     if sValue[i] in cValidFloatChrs then begin
  871.       result := result + sValue[i] ;
  872.     end ;
  873.   end ;
  874. end ;
  875.  
  876. //------------------------------------------------------------------------------
  877. procedure TBaseFloatEdit.setPrecision( iValue : integer ) ;
  878. var i : integer ;
  879. begin
  880.   FiPrecision := iValue ;
  881.   FsEditMask := cFloatEditMask ;
  882.   if FiPrecision > 0 then begin
  883.     FsEditMask := FsEditMask + '.' ;
  884.     for i := 1 to FiPrecision do begin
  885.       FsEditMask := FsEditMask + '0' ;
  886.     end ;
  887.   end ;
  888.   self.refresh ;
  889. end ;
  890.  
  891. //------------------------------------------------------------------------------
  892. procedure TBaseFloatEdit.refresh ;
  893. begin
  894.   self.asFloat := self.asFloat ;
  895. end ;
  896.  
  897. //------------------------------------------------------------------------------
  898. procedure TBaseFloatEdit.baseFloatKeyPress(Sender: TObject;var Key: Char);
  899. begin
  900.  
  901.   FsBeforeApplyKey := self.text ;
  902.  
  903.   // A non character key?
  904.   if ( ord( key ) < 32 ) or ( ord( key ) > 132 ) then begin
  905.     exit ;
  906.   end ;
  907.  
  908.   // A numeric key?
  909.   if not ( key in cValidFloatChrs ) then begin
  910.     key := char( 0 ) ;
  911.   end ;
  912.  
  913. end ;
  914.  
  915. //------------------------------------------------------------------------------
  916. procedure TBaseFloatEdit.baseFloatOnChange( sender : TObject ) ;
  917. var lReal : real ;
  918.     lIntPos : integer ;
  919. begin
  920.   lReal := self.AsFloat ;
  921.   if not self.withinMinMaxLimits( lReal ) then begin
  922.     lIntPos := self.selStart ;
  923.     self.text := FsBeforeApplyKey ;
  924.     self.selStart := lIntPos ;
  925.     messageBeep( 0 ) ;
  926.   end ;
  927. end ;
  928.  
  929. //------------------------------------------------------------------------------
  930. procedure TBaseFloatEdit.setTextAfter( sValue : string ) ;
  931. begin
  932.   FsTextAfter := sValue ;
  933.   self.refresh ;
  934. end ;
  935.  
  936. //------------------------------------------------------------------------------
  937. procedure TBaseFloatEdit.setTextBefore( sValue : string ) ;
  938. begin
  939.   FsTextBefore := sValue ;
  940.   self.refresh ;
  941. end ;
  942.  
  943. //------------------------------------------------------------------------------
  944. procedure TBaseFloatEdit.setApplyMask( bValue : boolean ) ;
  945. begin
  946.   FbApplyMask := bValue ;
  947.   if FbApplyMask then begin
  948.     FsEditMask  := cFloatEditMask ;
  949.   end else begin
  950.     FsEditMask  := '###0' ;
  951.   end ;
  952.   self.refresh ;
  953. end ;
  954.  
  955. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  956. //*
  957. //* TtiDBGrid
  958. //*
  959. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  960. constructor TtiDBGrid.create( owner : TComponent ) ;
  961. begin
  962.   inherited ;
  963.   onDrawColumnCell := customDrawCell ;
  964.   defaultDrawing := false ;
  965.   FBitmap    := TBitmap.create ;
  966. end ;
  967.  
  968. //------------------------------------------------------------------------------
  969. destructor TtiDBGrid.destroy ;
  970. begin
  971.   FBitmap.free ;
  972.   inherited ;
  973. end ;
  974.  
  975. //------------------------------------------------------------------------------
  976. procedure TtiDBGrid.customDrawCell(Sender: TObject; const Rect: TRect;
  977.       DataCol: Integer; Column: TColumn; State: TGridDrawState);
  978. var fontColor : TColor ;
  979.     cellColor : TColor ;
  980.     TextOrBitmap : TTextOrBitmap ;
  981. begin
  982.   if assigned( FOnCalcCellDispProps ) then begin
  983.     cellColor := canvas.brush.color ;
  984.     fontColor := canvas.font.color  ;
  985.     FOnCalcCellDispProps( sender,
  986.                           TTIDBGrid(column.grid).dataSource.dataSet,
  987.                           upperCase( column.fieldName ),
  988.                           fontColor, cellColor ) ;
  989.     if state = [] then begin
  990.       canvas.brush.color := cellColor ;
  991.       canvas.font.color  := fontColor ;
  992.     end else begin
  993.       canvas.brush.color := clHighLight ;
  994.       canvas.font.color  := clHighLightText ;
  995.     end ;
  996.   end ;
  997.  
  998.   if assigned( FOnCalcCellBitMap ) then begin
  999.     textOrBitmap := tobTextOnly ;
  1000.     FOnCalcCellBitMap( sender,
  1001.                        TTIDBGrid(column.grid).dataSource.dataSet,
  1002.                        upperCase( column.fieldName ),
  1003.                        FBitmap, TextOrBitmap ) ;
  1004.     self.drawBitmapInCell( Rect, DataCol, Column, State, textOrBitmap );
  1005.   end else begin
  1006.     self.DefaultDrawColumnCell( Rect, DataCol, Column, State );
  1007.   end ;
  1008. end ;
  1009.  
  1010. //------------------------------------------------------------------------------
  1011. procedure TtiDBGrid.drawBitmapInCell(const Rect: TRect; DataCol: Integer;
  1012.                                      Column: TColumn; State: TGridDrawState ;
  1013.                                      textOrBitmap : TTextOrBitmap );
  1014. var newRect : TRect ;
  1015.     iTop : integer ;
  1016. begin
  1017.  
  1018.   if textOrBitmap = tobTextOnly then begin
  1019.     self.DefaultDrawColumnCell( Rect, DataCol, Column, State ) ;
  1020.     exit ; // ==>
  1021.   end ;
  1022.  
  1023.   // Set so user can not edit a col with a bitmap, but causing probs saving
  1024.   // data to the underlying table.
  1025.   // column.readOnly := true ;
  1026.  
  1027.   if textOrBitmap = tobBitMapOnly then begin
  1028.     canvas.draw( rect.left+1, rect.top+1, FBitmap ) ;
  1029.     exit ; // ==>
  1030.   end ;
  1031.  
  1032.   if textOrBitmap = tobBoth then begin
  1033.     iTop := rect.bottom-FBitmap.height-1 ;
  1034.     FBitmap.transparentColor := canvas.brush.color ;
  1035.     canvas.draw( rect.left+1, iTop, FBitmap ) ;
  1036.     setRect( newRect, rect.left+2+FBitmap.width, rect.top,
  1037.              rect.right, rect.bottom ) ;
  1038.     self.DefaultDrawColumnCell( newRect, DataCol, Column, State ) ;
  1039.     exit ; // ==>
  1040.   end ;
  1041.  
  1042.   raise exception.create( 'Invalid textOrBitmap passed to TtiDBGrid.drawBitmapInCell' ) ;
  1043.  
  1044. end ;
  1045.  
  1046. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1047. //*
  1048. //* Dynamic Pick Lists
  1049. //*
  1050. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1051. //------------------------------------------------------------------------------
  1052. constructor TtiPickList.create( oOwner : TComponent ) ;
  1053. begin
  1054.   inherited create( oOwner ) ;
  1055.   with self do begin
  1056.     width := 217 ;
  1057.     height := 23 ;
  1058.     caption := ' ' ;
  1059.     bevelInner  := bvNone ;
  1060.     bevelOuter  := bvNone ;
  1061.     borderStyle := bsNone ;
  1062.   end ;
  1063.  
  1064.   oEdit     := TEdit.create( self ) ;
  1065.   with oEdit do begin
  1066.     left := 1 ;
  1067.     top  := 1 ;
  1068.     height := self.height-2;
  1069.     width  := self.width - 3 - 17 ;
  1070.     parent := self ;
  1071.     borderStyle := bsSingle ;
  1072.     ctl3D := true ;
  1073.     onClick := speedButtonClick ;
  1074.     onKeyPress := editKeyPress ;
  1075.     onKeyDown := editKeyDown ;
  1076.   end ;
  1077.  
  1078.   oSpeedButton     := TSpeedButton.create( self ) ;
  1079.   with oSpeedButton do begin
  1080.     left := self.width - 17 ;
  1081.     top  := 1 ;
  1082.     width := 17 ;
  1083.     height := self.Height-2 ;
  1084.     parent := self ;
  1085.     try
  1086.       glyph.loadFromFile( 'tri_down.bmp' ) ;
  1087.     except
  1088.       caption := 'v' ;
  1089.     end ;
  1090.     onClick  := speedButtonClick ;
  1091.   end ;
  1092.  
  1093.   oTable      := TTable.create( self )        ;
  1094.   with oTable do begin
  1095.   showMessage( 'Requires work !' ) ;
  1096.   //    dataBaseName := cDatabaseMain ;
  1097.     tableType    := ttParadox     ;
  1098.   end ;
  1099.  
  1100.   self.searchText := '' ;
  1101.  
  1102.   oDataSource := TDataSource.create( self )   ;
  1103.   oDataSource.dataSet := oTable               ;
  1104.  
  1105.   oForm       := TForm.create( self )         ;
  1106.   with oForm do begin
  1107.     borderStyle := bsNone ;
  1108.     height      := 200 ;
  1109.     onDeactivate := oFormDeactivate ;
  1110.   end ;
  1111.  
  1112.   oDBGrid     := TDBGrid.create( self )       ;
  1113.   with oDBGrid do begin
  1114.     dataSource := oDataSource ;
  1115.     parent     := oForm ;
  1116.     align      := alClient ;
  1117.     options    := [dgTitles,dgColLines,dgRowLines,dgAlwaysShowSelection,
  1118.                    dgRowSelect] ;
  1119.     onKeyPress := DBGridKeyPress ;
  1120.     onDblClick := DBGridDblClick ;
  1121.   end ;
  1122. end ;
  1123.  
  1124. //------------------------------------------------------------------------------
  1125. destructor  TtiPickList.free ;
  1126. begin
  1127.   oEdit.free          ;
  1128.   oSpeedButton.free   ;
  1129.   oTable.free         ;
  1130.   oDataSource.free    ;
  1131.   oForm.free          ;
  1132.   oDBGrid.free        ;
  1133. end ;
  1134.  
  1135. //------------------------------------------------------------------------------
  1136. procedure TtiPickList.setTableName( sValue : string ) ;
  1137. begin
  1138.   oTable.close ;
  1139.   oTable.tableName := sValue ;
  1140.   openTable ;
  1141. end ;
  1142.  
  1143. //------------------------------------------------------------------------------
  1144. function TtiPickList.getTableName : string ;
  1145. begin
  1146.   result := oTable.tableName ;
  1147. end ;
  1148.  
  1149. //------------------------------------------------------------------------------
  1150. procedure TtiPickList.setIndexName( sValue : string ) ;
  1151. begin
  1152.   oTable.indexName := sValue ;
  1153. end ;
  1154.  
  1155. //------------------------------------------------------------------------------
  1156. function TtiPickList.getIndexName : string ;
  1157. begin
  1158.   result := oTable.indexName ;
  1159. end ;
  1160.  
  1161. //------------------------------------------------------------------------------
  1162. function  TtiPickList.getText : string ;
  1163. begin
  1164.   if oEdit.text = '' then begin
  1165.     result := '' ;
  1166.     exit ; //==>
  1167.   end ;
  1168.   try
  1169.     result := oTable.fieldByName( self.returnField ).asString ;
  1170.   except
  1171.     result := '' ;
  1172.   end ;
  1173. end ;
  1174.  
  1175. //------------------------------------------------------------------------------
  1176. procedure TtiPickList.setSearchText( sValue : string ) ;
  1177. begin
  1178.   FsSearchText := upperCase( sValue ) ;
  1179. end ;
  1180.  
  1181. //------------------------------------------------------------------------------
  1182. procedure TtiPickList.setRange( sValue : string ) ;
  1183. begin
  1184.   FsRange := sValue ;
  1185.   try
  1186.     oTable.setRange([sValue], [sValue]) ;
  1187.   except
  1188. //   on e:exception do uAppException( 'Unable to set range to ' +
  1189. //                                   oTable.tablename +
  1190. //                                   ' <' + sValue + '>', e ) ;
  1191.   end ;
  1192. end ;
  1193.  
  1194. //------------------------------------------------------------------------------
  1195. procedure TtiPickList.setText( sValue : string ) ;
  1196. begin
  1197.  
  1198.   try
  1199.     self.openTable ;
  1200.     self.searchText := sValue ;
  1201.     if self.searchText = '' then begin
  1202.       oEdit.text := '' ;
  1203.       exit ; //==>
  1204.     end ;
  1205.     if self.range <> '' then begin
  1206.       oTable.findNearest( [ self.range, self.searchText ] ) ;
  1207.     end else begin
  1208.       oTable.findNearest( [ self.searchText ] ) ;
  1209.     end ;
  1210.     self.copyTextToEdit ;
  1211.   except
  1212.     self.searchText := '' ;
  1213.     oEdit.text := '' ;
  1214.   end ;
  1215. end ;
  1216.  
  1217. //------------------------------------------------------------------------------
  1218. procedure TtiPickList.speedButtonClick( sender : TObject ) ;
  1219. var pointTemp : TPoint ;
  1220. begin
  1221.  
  1222.   pointTemp   :=  clientToScreen( point( oEdit.left,
  1223.                                          oEdit.top + oEdit.height )) ;
  1224.   oForm.top         :=  pointTemp.Y ;
  1225.   oForm.left        :=  pointTemp.X ;
  1226.   oForm.font.assign( self.font ) ;
  1227.   self.openTable ;
  1228.   oForm.show ;
  1229. end ;
  1230.  
  1231. //------------------------------------------------------------------------------
  1232. procedure TtiPickList.openTable ;
  1233. var i : integer ;
  1234.     sFieldName  : string ;
  1235. begin
  1236.  
  1237.   if oTable.state <> dsInactive then begin
  1238.     exit ;
  1239.   end ;
  1240.  
  1241.   if gridFieldNames = '' then begin
  1242.     exit ; // ==> 
  1243.   end ;
  1244.  
  1245.   try
  1246.     with oTable do begin
  1247.       open ;
  1248.  
  1249.       if self.range <> '' then begin
  1250.         oTable.setRange([self.range], [self.range]) ;
  1251.       end ;
  1252.  
  1253.       for i := 0 to fieldCount - 1 do begin
  1254.         fields[i].visible := false ;
  1255.       end ;
  1256.       for i := 1 to tiNumToken( self.gridFieldNames, ';' ) do begin
  1257.         sFieldName := tiToken( self.gridFieldNames, ';', i ) ;
  1258.         fieldByName( sFieldName ).visible := true ;
  1259.         fieldByName( sFieldName ).displayLabel
  1260.           := tiToken( self.gridDisplayLables, ';', i ) ;
  1261.       end ;
  1262.     end ;
  1263.     oForm.width := self.width ;
  1264.   except end ;
  1265.  
  1266. end ;
  1267.  
  1268. //------------------------------------------------------------------------------
  1269. procedure TtiPickList.oFormDeactivate(Sender: TObject);
  1270. begin
  1271.   oForm.hide ;
  1272.   oEdit.setFocus ;
  1273.   oEdit.selLength := 0 ;
  1274. end;
  1275.  
  1276. //------------------------------------------------------------------------------
  1277. procedure TtiPickList.DBGridKeyPress( Sender: TObject; var Key: Char );
  1278. begin
  1279.  
  1280.   self.openTable ;
  1281.  
  1282.   // Back space key
  1283.   if key = chr( 8 ) then begin
  1284.     self.searchText := '' ;
  1285.     try
  1286.       oTable.first ;
  1287.     except end ;
  1288.     oEdit.text := '' ;
  1289.     exit ;
  1290.   end ;
  1291.  
  1292.   // Return key
  1293.   if key = chr( 13 ) then begin
  1294.     DBGridDblClick( sender ) ;
  1295.     exit ;
  1296.   end ;
  1297.  
  1298.   self.searchText := self.searchText + upperCase( key ) ;
  1299.  
  1300.   try
  1301.     if self.range <> '' then begin
  1302.       oTable.findNearest( [ self.range, self.searchText ] ) ;
  1303.     end else begin
  1304.       oTable.findNearest( [ self.searchText ] ) ;
  1305.     end ;
  1306.   except end ;
  1307.   self.copyTextToEdit ;
  1308.  
  1309. end;
  1310.  
  1311. //------------------------------------------------------------------------------
  1312. procedure TtiPickList.DBGridDblClick(Sender: TObject);
  1313. begin
  1314.   self.copyTextToEdit ;
  1315.   oFormDeactivate( sender ) ;
  1316.   if assigned( FOnChange ) then begin
  1317.     FOnChange( self ) ;
  1318.   end ;
  1319. end;
  1320.  
  1321. //------------------------------------------------------------------------------
  1322. procedure TtiPickList.EditKeyPress( Sender: TObject; var Key: Char );
  1323. begin
  1324.   case ord( key ) of
  1325.     13 : speedButtonClick( sender ) ;
  1326.      8 : begin
  1327.            oEdit.text := '' ;
  1328.            self.searchText := '' ;
  1329.          end
  1330.   else
  1331.     DBGridKeyPress( sender, key ) ;
  1332.     self.copyTextToEdit ;
  1333.   end ;
  1334.   key := #0 ;
  1335. end;
  1336.  
  1337. //------------------------------------------------------------------------------
  1338. procedure TtiPickList.EditKeyDown( Sender: TObject; var Key: word ;
  1339.                                  Shift: TShiftState );
  1340. begin
  1341.   if key = VK_DOWN then begin
  1342.     speedButtonClick( sender ) ;
  1343.   end ;
  1344.  
  1345. end;
  1346.  
  1347. //------------------------------------------------------------------------------
  1348. procedure TtiPickList.CopyTextToEdit ;
  1349. var i : integer ;
  1350.     sText : string ;
  1351.     sFieldName : string ;
  1352. begin
  1353.  
  1354.   if self.editFieldNames = '' then begin
  1355.     oEdit.text := '' ;
  1356.     exit ; // ==> 
  1357.   end ;
  1358.  
  1359.   try
  1360.     sText := '' ;
  1361.     for i := 1 to tiNumToken( self.editFieldNames, ';' ) do begin
  1362.       sFieldName := tiToken( self.editFieldNames, ';', i ) ;
  1363.       if i <> 1 then begin
  1364.         sText := sText + ' - ' ;
  1365.       end ;
  1366.       sText := sText + oTable.fieldByName( sFieldName ).asString ;
  1367.     end ;
  1368.     oEdit.text := sText ;
  1369.   except
  1370.     oEdit.text := '' ;
  1371.   end ;
  1372. end ;
  1373.  
  1374. //------------------------------------------------------------------------------
  1375. procedure TtiPickList.WMSize( var Message : TWMSize );
  1376. begin
  1377.   inherited;
  1378.   if self.height < cMinHeight then begin
  1379.     self.height := cMinHeight ;
  1380.   end ;
  1381.  
  1382.   if self.width < cMinWidth then begin
  1383.     self.width := cMinWidth ;
  1384.   end ;
  1385.  
  1386.   oEdit.height   := self.height -2;
  1387.   oEdit.width    := self.width - 3 - 17 ;
  1388.  
  1389.   oSpeedButton.left   := self.width - 17 ;
  1390.   oSpeedButton.height := self.Height -2 ;
  1391.  
  1392. end;
  1393.  
  1394. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1395. //*
  1396. //* TAbort
  1397. //*
  1398. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1399. //------------------------------------------------------------------------------
  1400. constructor TtiAbort.create( oOwner : TComponent ) ;
  1401. begin
  1402.   inherited create( oOwner ) ;
  1403.   oForm := TForm.create( self ) ;
  1404.   oBitBtnAbort := TBitBtn.create( self ) ;
  1405.   oGauge       := TGauge.create( self ) ;
  1406.  
  1407.   self.abort := false ;
  1408.  
  1409.   with oForm do begin
  1410.     borderStyle := bsDialog ;
  1411.     borderIcons := [] ;
  1412.     caption := 'Abort dialogue' ;
  1413.     font.name := 'Arial' ;
  1414.     font.size := 9 ;
  1415.     font.color := clNavy ;
  1416.     height     := 130  ;
  1417.     width      := 300 ;
  1418.     position   := poScreenCenter ;
  1419.     formStyle  := fsStayOnTop ;
  1420.     
  1421.     with oGauge do begin
  1422.       parent := oForm ;
  1423.       top    := 20   ;
  1424.       left   := 10   ;
  1425.       width  := 280  ;
  1426.       height := 20   ;
  1427.       maxValue := 100 ;
  1428.       color    := clNavy ;
  1429.       foreColor:= clNavy ;
  1430.       showText := false  ;
  1431.     end ;
  1432.  
  1433.     with oBitBtnAbort do begin
  1434.       parent := oForm ;
  1435.       top    := 60 ;
  1436.       left   := 110 ;
  1437.       width  := 80 ;
  1438.       height := 25 ;
  1439.       kind   := bkAbort ;
  1440.       onClick := bitBtnAbortClick ;
  1441.     end ;
  1442.   end ;
  1443.   application.processMessages ;
  1444. end ;
  1445.  
  1446. //------------------------------------------------------------------------------
  1447. destructor TtiAbort.destroy ;
  1448. begin
  1449.   oForm.close       ;
  1450.   oBitBtnAbort.free ;
  1451.   oGauge.free       ;
  1452.   oForm.free        ;
  1453.   inherited destroy    ;
  1454. end ;
  1455.  
  1456. //------------------------------------------------------------------------------
  1457. procedure TtiAbort.bitBtnAbortClick( sender : TObject ) ;
  1458. begin
  1459.   oForm.formStyle := fsNormal ;
  1460.   if messageDlg( 'Are you sure you want to abort this process ?',
  1461.                  mtConfirmation,
  1462.                  [mbNo, mbYes],
  1463.                  0 ) = mrYes then begin ;
  1464.     oForm.hide ;
  1465.     self.abort := true ;
  1466.   end ;
  1467. end ;
  1468.  
  1469. //------------------------------------------------------------------------------
  1470. procedure TtiAbort.pPutProgress( iProgress : longInt ) ;
  1471. begin
  1472.   oGauge.progress := iProgress ;
  1473. end ;
  1474.  
  1475. //------------------------------------------------------------------------------
  1476. function  TtiAbort.pGetProgress : longInt ;
  1477. begin
  1478.   result := oGauge.progress ;
  1479. end ;
  1480.  
  1481. //------------------------------------------------------------------------------
  1482. procedure TtiAbort.pPutMaxValue( iMaxValue : longInt ) ;
  1483. begin
  1484.   oGauge.maxValue := iMaxValue ;
  1485. end ;
  1486.  
  1487. //------------------------------------------------------------------------------
  1488. function  TtiAbort.pGetMaxValue : longInt ;
  1489. begin
  1490.   result := oGauge.maxValue ;
  1491. end ;
  1492.  
  1493. //------------------------------------------------------------------------------
  1494. function TtiAbort.incGauge : boolean ;
  1495. begin
  1496.   oGauge.progress := oGauge.progress + 1 ;
  1497.   if oGauge.progress >= oGauge.maxValue
  1498.   then oGauge.progress := 0 ;
  1499.   application.processMessages ;
  1500.   result := not( self.abort ) ;
  1501. end ;
  1502.  
  1503. //------------------------------------------------------------------------------
  1504. function TtiAbort.Inc : boolean ;
  1505. begin
  1506.   result := IncGauge ;
  1507. end ;
  1508.  
  1509. //------------------------------------------------------------------------------
  1510. procedure TtiAbort.hide ;
  1511. begin
  1512.   oForm.hide ;
  1513. end ;
  1514.  
  1515. //------------------------------------------------------------------------------
  1516. procedure TtiAbort.show( sCaption : string ;iMaxValue : longInt ) ;
  1517. begin
  1518.   oForm.caption := ' ' + sCaption ;
  1519.   self.maxValue := iMaxValue ;
  1520.   self.progress := 0 ;
  1521.   oForm.show ;
  1522.   application.processMessages ;
  1523. end ;
  1524.  
  1525. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1526. //*
  1527. //* TCustomPicker
  1528. //*
  1529. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1530. //------------------------------------------------------------------------------
  1531. constructor TtiCustomPicker.create( Owner : TComponent ) ;
  1532. begin
  1533.   inherited create( Owner ) ;
  1534.   ControlStyle := ControlStyle - [csSetCaption] ;
  1535.  
  1536.   with self do begin
  1537.     caption     := ' ' ;
  1538.     BevelOuter  := bvNone ;
  1539.     BorderWidth := 1 ;
  1540.     BorderStyle := bsSingle ;
  1541.     height      := cMinHeight  ;
  1542.     width       := cMinWidth   ;
  1543.   end ;
  1544.  
  1545.   oSpeedButton := TSpeedButton.create( self ) ;
  1546.   with oSpeedButton do begin
  1547.     top  := 0 ;
  1548.     width := 16 ;
  1549.     parent := self ;
  1550.     glyph.handle := loadBitmap( HInstance, 'BMTHREEDOTS' ) ;
  1551.     numGlyphs := 1 ;
  1552.     onClick  := buttonClick ;
  1553.   end ;
  1554.  
  1555.   oEdit := TEdit.create( self ) ;
  1556.   with oEdit do begin
  1557.     left := 0 ;
  1558.     top  := 0 ;
  1559.     parent := self ;
  1560.     borderStyle := bsNone ;
  1561.     ctl3D := false ;
  1562.     onClick  := buttonClick ;
  1563.     onChange := editChange ;
  1564.   end ;
  1565.  
  1566. end ;
  1567.  
  1568. //------------------------------------------------------------------------------
  1569. procedure TtiCustomPicker.buttonClick( sender : TObject ) ;
  1570. begin
  1571.   //
  1572. end;
  1573.  
  1574. //------------------------------------------------------------------------------
  1575. procedure TtiCustomPicker.editChange(sender: TObject);
  1576. begin
  1577.   if assigned( FOnChange ) then FOnChange( sender ) ;
  1578. end;
  1579.  
  1580. //------------------------------------------------------------------------------
  1581. procedure TtiCustomPicker.setText( sValue : string ) ;
  1582. begin
  1583.   oEdit.text := sValue ;
  1584. end ;
  1585.  
  1586. //------------------------------------------------------------------------------
  1587. function  TtiCustomPicker.getText : string ;
  1588. begin
  1589.   result := oEdit.text ;
  1590. end ;
  1591.  
  1592. //------------------------------------------------------------------------------
  1593. procedure TtiCustomPicker.WMSize( var Message : TWMSize );
  1594. begin
  1595.   inherited;
  1596.   if self.height < cMinHeight then begin
  1597.     self.height := cMinHeight ;
  1598.   end ;
  1599.  
  1600.   if self.width < cMinWidth then begin
  1601.     self.width := cMinWidth ;
  1602.   end ;
  1603.  
  1604.   oSpeedButton.left := self.clientWidth - oSpeedButton.width  ;
  1605.   oSpeedButton.height := self.clientHeight ;
  1606.  
  1607.   oEdit.height := self.clientHeight ;
  1608.   oEdit.width  := self.clientWidth - oSpeedButton.width ;
  1609.  
  1610. end;
  1611.  
  1612. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1613. //*
  1614. //* TPickPrinter
  1615. //*
  1616. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1617. //------------------------------------------------------------------------------
  1618. procedure TtiPickPrinter.readItems ;
  1619. begin
  1620.   Items.Clear ;
  1621.   self.items.assign( printer.printers ) ;
  1622. end ;
  1623.  
  1624. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1625. //*
  1626. //* TPickDirectory
  1627. //*
  1628. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1629. //------------------------------------------------------------------------------
  1630. constructor TtiPickDirectory.create( Owner : TComponent ) ;
  1631. //var directoryBuffer : array[0..255] of char ;
  1632. begin
  1633.   inherited create( Owner ) ;
  1634.   //getCurrentDirectory( 255, directoryBuffer ) ;
  1635. //  self.text := string( directoryBuffer ) ;
  1636.   FbCreateDir := false ;
  1637.   self.onExit := pickDirectoryOnExit ;
  1638. end ;
  1639.  
  1640. //------------------------------------------------------------------------------
  1641. procedure TtiPickDirectory.loaded ;
  1642. var directoryBuffer : array[0..255] of char ;
  1643. begin
  1644.   inherited loaded ;
  1645.   getCurrentDirectory( 255, directoryBuffer ) ;
  1646.   self.text := string( directoryBuffer ) ;
  1647. end ;
  1648.  
  1649. //------------------------------------------------------------------------------
  1650. procedure TtiPickDirectory.buttonClick( sender : TObject ) ;
  1651. var formPickDir  : TForm ;
  1652.     bitBtnCancel : TBitBtn ;
  1653.     bitBtnOK     : TBitBtn ;
  1654.     directoryListBox : TDirectoryListBox ;
  1655.     driveComboBox    : TDriveComboBox    ;
  1656.     label1           : TLabel            ;
  1657.     label2           : TLabel            ;
  1658.     labelDir         : TLabel            ;
  1659. begin
  1660.   formPickDir := TForm.create( self ) ;
  1661.   try
  1662.     with formPickDir do begin
  1663.       borderIcons := [biSystemMenu] ;
  1664.       borderStyle := bsDialog ;
  1665.       caption     := 'Pick a directory' ;
  1666.       position    := poScreenCenter ;
  1667.       font.name := 'Arial' ;
  1668.       font.size  := 9 ;
  1669.       height     := 273 ;
  1670.       width      := 301 ;
  1671.     end ;
  1672.  
  1673.     labelDir := TLabel.create( formPickDir ) ;
  1674.     with labelDir do begin
  1675.       parent := formPickDir ;
  1676.       top  := 24 ;
  1677.       left := 16 ;
  1678.       font.style := [fsBold] ;
  1679.     end ;
  1680.  
  1681.     directoryListBox := TDirectoryListBox.create( formPickDir ) ;
  1682.     with directoryListBox do begin
  1683.       parent := formPickDir ;
  1684.       top  := 48   ;
  1685.       left := 16   ;
  1686.       width := 145 ;
  1687.       height := 129 ;
  1688.       directory := oEdit.text ;
  1689.       dirLabel  := labelDir ;
  1690.     end ;
  1691.  
  1692.     driveComboBox := TDriveComboBox.create( formPickDir ) ;
  1693.     with driveComboBox do begin
  1694.       parent := formPickDir ;
  1695.       top  := 208 ;
  1696.       left := 16 ;
  1697.       width := 145 ;
  1698.       height := 21 ;
  1699.       dirList  := directoryListBox ;
  1700.     end ;
  1701.  
  1702.     bitBtnOK := TBitBtn.create( formPickDir ) ;
  1703.     with bitBtnOK do begin
  1704.       parent := formPickDir ;
  1705.       top  := 48 ;
  1706.       left := 184 ;
  1707.       width := 81 ;
  1708.       height := 25 ;
  1709.       kind := bkOK ;
  1710.       modalResult := mrOK ;
  1711.       caption := '&OK' ;
  1712.       default     := false ;
  1713.     end ;
  1714.  
  1715.     bitBtnCancel := TBitBtn.create( formPickDir ) ;
  1716.     with bitBtnCancel do begin
  1717.       parent := formPickDir ;
  1718.       top  := 80 ;
  1719.       left := 184 ;
  1720.       width := 81 ;
  1721.       height := 25 ;
  1722.       kind := bkCancel ;
  1723.       modalResult := mrCancel ;
  1724.       caption := '&Cancel' ;
  1725.       default     := false ;
  1726.       font.style := [fsBold] ;
  1727.     end ;
  1728.  
  1729.     label1 := TLabel.create( formPickDir ) ;
  1730.     with label1 do begin
  1731.       parent := formPickDir ;
  1732.       top  :=  8 ;
  1733.       left := 16 ;
  1734.       caption := 'Folders' ;
  1735.       font.style := [fsBold] ;
  1736.     end ;
  1737.  
  1738.     label2 := TLabel.create( formPickDir ) ;
  1739.     with label2 do begin
  1740.       parent := formPickDir ;
  1741.       top  := 184 ;
  1742.       left := 16 ;
  1743.       caption := 'Drives' ;
  1744.       font.style := [fsBold] ;
  1745.     end ;
  1746.  
  1747.     directoryListBox.directory := oEdit.text ;
  1748.     if formPickDir.showModal = mrOK then begin
  1749.       self.text := directoryListBox.directory ;
  1750.     end ;
  1751.   finally
  1752.     formPickDir.free ;
  1753.   end ;
  1754. end ;
  1755.  
  1756. //------------------------------------------------------------------------------
  1757. procedure TtiPickDirectory.PickDirectoryOnExit( sender : TObject ) ;
  1758. var sDirectory : string ;
  1759. begin
  1760.  
  1761.   if not FbCreateDir then
  1762.     exit ;
  1763.  
  1764.   sDirectory := self.text ;
  1765.   if not DirectoryExists( sDirectory ) then begin
  1766.     if not messageDlg( 'Directory <' + sDirectory +
  1767.                        '> does not exist.' + #13 +
  1768.                        'Do you want to create it ?',
  1769.                        mtConfirmation, [mbYes, mbNo], 0 ) = mrYes then begin
  1770.       self.setFocus ;
  1771.       exit ; //==>
  1772.     end ;
  1773.     ForceDirectories( sDirectory ) ;
  1774.     if not DirectoryExists( sDirectory ) then begin
  1775.       raise exception.create( 'Can not create directory <' +
  1776.                               sDirectory + '>' ) ;
  1777.     end ;
  1778.   end ;
  1779. end ;
  1780.  
  1781. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1782. //*
  1783. //* TPickFile
  1784. //*
  1785. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1786. constructor TtiPickFile.create( owner : TComponent ) ;
  1787. begin
  1788.   inherited create( owner ) ;
  1789.   FsDefaultExt := '' ;
  1790.   FsFilter     := 'All files|*.*' ;
  1791.   FsTitle      := '' ;
  1792. end ;
  1793.  
  1794. //------------------------------------------------------------------------------
  1795. procedure TtiPickFile.buttonClick( sender : TObject ) ;
  1796. var oOpenDialog : TOpenDialog ;
  1797. begin
  1798.   oOpenDialog := TOpenDialog.create( self ) ;
  1799.   try
  1800.     oOpenDialog.title := self.title ;
  1801.     oOpenDialog.Filter := self.filter ;
  1802.     oOpenDialog.defaultExt := self.defaultExt ;
  1803.     oOpenDialog.fileName := self.text ;
  1804.     if oOpenDialog.execute then begin
  1805.       self.text := oOpenDialog.fileName ;
  1806.     end ;
  1807.   finally
  1808.     oOpenDialog.free ;
  1809.   end ;
  1810. end ;
  1811.  
  1812. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1813. //*
  1814. //* TAmuseUser
  1815. //*
  1816. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1817. //------------------------------------------------------------------------------
  1818. constructor TtiAmuseUser.create( oOwner : TComponent ) ;
  1819. begin
  1820.   inherited create( oOwner ) ;
  1821.   oForm := TForm.create( self ) ;
  1822.   with oForm do begin
  1823.     height := 142 ;
  1824.     width  := 301 ;
  1825.     borderIcons := [] ;
  1826.     borderStyle := bsDialog ;
  1827.     formStyle := fsStayOnTop ;
  1828.     position  := poScreenCenter ;
  1829.     font.name := 'Arial' ;
  1830.     font.size  := 9 ;
  1831.     caption := 'Long process in progress...' ;
  1832.   end ;
  1833.  
  1834.   oGauge := TGauge.create( self ) ;
  1835.   with oGauge do begin
  1836.     parent := oForm ;
  1837.     top := 56 ;
  1838.     left := 16 ;
  1839.     height := 25 ;
  1840.     width  := 257 ;
  1841.     showText := false ;
  1842.     maxValue := 100 ;
  1843.     foreColor := clNavy ;
  1844.   end ;
  1845.  
  1846.   oLabel := TLabel.create( self ) ;
  1847.   with oLabel do begin
  1848.     parent := oForm ;
  1849.     top := 16 ;
  1850.     left := 24 ;
  1851.     width := 257 ;
  1852.     alignment := taCenter ;
  1853.     caption := 'Long process in progress...' ;
  1854.   end ;
  1855.  
  1856.   oTimer := TTimer.create( self ) ;
  1857.   with oTimer do begin
  1858.     onTimer := oTimerTimer ;
  1859.     interval := 25 ;
  1860.   end ;
  1861.  
  1862. end ;
  1863.  
  1864. //------------------------------------------------------------------------------
  1865. destructor TtiAmuseUser.free ;
  1866. begin
  1867.   oForm.free  ;
  1868.   oGauge.free ;
  1869.   oLabel.free ;
  1870.   oTimer.free ;
  1871.   inherited free      ;
  1872. end ;
  1873.  
  1874. //------------------------------------------------------------------------------
  1875. function TtiAmuseUser.getCaption : string ;
  1876. begin
  1877.   result := oForm.caption ;
  1878. end ;
  1879.  
  1880. //------------------------------------------------------------------------------
  1881. procedure TtiAmuseUser.setCaption( sValue : string ) ;
  1882. begin
  1883.   oForm.caption := sValue ;
  1884.   self.messageLine := sValue ;
  1885. end ;
  1886.  
  1887. //------------------------------------------------------------------------------
  1888. function TtiAmuseUser.getMessageLine : string ;
  1889. begin
  1890.   result := oLabel.caption ;
  1891.   oLabel.alignment := taCenter ;
  1892. end ;
  1893.  
  1894. //------------------------------------------------------------------------------
  1895. procedure TtiAmuseUser.setMessageLine( sValue : string ) ;
  1896. begin
  1897.   oLabel.caption := sValue ;
  1898. end ;
  1899.  
  1900. //------------------------------------------------------------------------------
  1901. procedure TtiAmuseUser.setEnabled( bValue : boolean ) ;
  1902. begin
  1903.   if bValue then begin
  1904.     oForm.show ;
  1905.     oTimer.enabled := true ;
  1906.     screen.cursor := crHourGlass ;
  1907.   end else begin
  1908.     oForm.hide ;
  1909.     oTimer.enabled := false ;
  1910.     screen.cursor := crDefault ;
  1911.   end ;
  1912.   application.processMessages ;
  1913. end ;
  1914.  
  1915. //------------------------------------------------------------------------------
  1916. function TtiAmuseUser.getEnabled : boolean ;
  1917. begin
  1918.   result := oForm.visible ;
  1919. end ;
  1920.  
  1921. //------------------------------------------------------------------------------
  1922. procedure TtiAmuseUser.oTimerTimer( sender: TObject ) ;
  1923. begin
  1924.   if oGauge.progress <> oGauge.maxValue then begin
  1925.     oGauge.progress := oGauge.progress + 1 ;
  1926.   end else begin
  1927.     oGauge.progress := 0 ;
  1928.     if oGauge.foreColor = clWhite then begin
  1929.       oGauge.foreColor := clNavy ;
  1930.       oGauge.backColor := clWhite ;
  1931.     end else begin
  1932.       oGauge.foreColor := clWhite ;
  1933.       oGauge.backColor := clNavy ;
  1934.     end ;
  1935.   end ;
  1936. end;
  1937.  
  1938. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1939. //*
  1940. //* TtiHistoryComboBox
  1941. //*
  1942. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  1943. constructor TtiHistoryComboBox.create( owner : TComponent ) ;
  1944. begin
  1945.   inherited create( owner ) ;
  1946.   self.onExit := historyComboBoxExit ;
  1947.   FiHistoryCount := 5 ;
  1948. end ;
  1949.  
  1950. //------------------------------------------------------------------------------
  1951. destructor TtiHistoryComboBox.destroy ;
  1952. begin
  1953.   oReg.free ;
  1954.   inherited destroy ;
  1955. end ;
  1956.  
  1957. //------------------------------------------------------------------------------
  1958. procedure TtiHistoryComboBox.loaded ;
  1959. var i : integer ;
  1960.     sItem : string ;
  1961. begin
  1962.   inherited loaded ;
  1963.   oReg := TRegINIFile.create( tiRemoveExtension(
  1964.                                 extractFileName( application.exeName ))) ;
  1965.   self.items.clear ;
  1966.   for i := 0 to FiHistoryCount-1 do begin
  1967.     sItem    := oReg.readString( self.owner.name, self.name + intToStr( i+1 ), '' ) ;
  1968.     if sItem = '' then begin
  1969.       break ; //==>
  1970.     end ;
  1971.     self.items.add( sItem ) ;
  1972.   end ;
  1973.   self.text := oReg.readString( self.owner.name, self.name + '0', '' ) ;
  1974. end;
  1975.  
  1976. //------------------------------------------------------------------------------
  1977. procedure TtiHistoryComboBox.historyComboBoxExit( sender : TObject ) ;
  1978. var i : integer ;
  1979. begin
  1980.  
  1981.   try
  1982.     if assigned( onValidate ) then onValidate( self ) ;
  1983.   except
  1984.     on e:exception do begin
  1985.       self.setFocus ;
  1986.       messageDlg( e.message,
  1987.                   mtError, [mbOK],0 ) ;
  1988.       raise ;
  1989.     end ;
  1990.   end ;
  1991.  
  1992.   if self.items.indexOf( self.text ) = -1 then begin
  1993.     self.items.insert( 0, self.text ) ;
  1994.   end ;
  1995.   while self.items.count > FiHistoryCount do begin
  1996.     self.items.delete( self.items.count-1 ) ;
  1997.   end ;
  1998.  
  1999.   for i := 0 to self.items.count - 1 do begin
  2000.     oReg.writeString( self.owner.name,
  2001.                       self.name + intToStr( i+1 ),
  2002.                       self.items[i] ) ;
  2003.   end ;
  2004.   oReg.writeString( self.owner.name,
  2005.                     self.name + '0',
  2006.                     self.text ) ;
  2007.  
  2008. end ;
  2009.  
  2010. //------------------------------------------------------------------------------
  2011. procedure TtiHistoryComboBox.SetHistoryCount(const iValue: integer);
  2012. begin
  2013.   if iValue < 5 then begin
  2014.     FiHistoryCount := 5 ;
  2015.     exit ;
  2016.   end ;
  2017.   if iValue > 20 then begin
  2018.     FiHistoryCount := 20 ;
  2019.     exit ;
  2020.   end ;
  2021.   FiHistoryCount := iValue ;
  2022. end;
  2023.  
  2024. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2025. //*
  2026. //* TDirectoryTree
  2027. //*
  2028. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2029. {
  2030. constructor TDirectory.createExt(const pStrDirectory: string);
  2031. begin
  2032.   inherited create ;
  2033.   Name := pStrDirectory ;
  2034. end;
  2035.  
  2036. //------------------------------------------------------------------------------
  2037. function TDirectory.TopOfPath : string;
  2038. var i : integer ;
  2039.     lIntPos : integer ;
  2040. begin
  2041.   lIntPos := -1 ;
  2042.   for i := length( Name ) downto 1 do begin
  2043.     if copy( Name, i, 1 ) = '\' then begin
  2044.       lIntPos := i + 1 ;
  2045.       break ; //==>
  2046.     end ;
  2047.   end ;
  2048.  
  2049.   if lIntPos <> -1 then
  2050.     result := copy( Name, lIntPos, length( Name ) - lIntPos + 1 )
  2051.   else
  2052.     result := '' ;
  2053.  
  2054. end;
  2055.  
  2056. //------------------------------------------------------------------------------
  2057. function TDirectory.NameUpper : string;
  2058. begin
  2059.   result := upperCase( Name ) ;
  2060. end;
  2061.  
  2062. //------------------------------------------------------------------------------
  2063. function TDirectory.DirToStringList( const pStrDirectory : string ) : TStringList ;
  2064. var i : integer ;
  2065.     iPos : integer ;
  2066.     lStrDirPart : string ;
  2067.     lStrDirFull : string ;
  2068. begin
  2069.   result := TStringList.create ;
  2070.   lStrDirFull := pStrDirectory ;
  2071.   for i := 1 to length( pStrDirectory ) do begin
  2072.     iPos := pos( '\', lStrDirFull ) ;
  2073.     if iPos <> 0 then begin
  2074.       lStrDirPart := copy( lStrDirFull, 1, iPos-1 ) ;
  2075.       lStrDirFull := copy( lStrDirFull, iPos+1, length( lStrDirFull ) + 1 ) ;
  2076.       result.Add( lStrDirPart ) ;
  2077.     end else begin
  2078.       result.Add( lStrDirFull ) ;
  2079.       break ; //==>
  2080.     end ;
  2081.   end ;
  2082. end ;
  2083.  
  2084. //------------------------------------------------------------------------------
  2085. function TDirectory.IsRootInDir(const pStrDirectory: string): boolean;
  2086. var lslCurrentDir : TStringList ;
  2087.     lslCompDir    : TStringList ;
  2088.     i : integer ;
  2089. begin
  2090.   result := true ;
  2091.   lslCurrentDir := DirToStringList( NameUpper ) ;
  2092.   try
  2093.     lslCompDir := DirToStringList( upperCase( pStrDirectory )) ;
  2094.     try
  2095.       for i := 0 to min( lslCurrentDir.Count-1, lslCompDir.Count-1 ) do begin
  2096.         if lslCurrentDir.Strings[i] <> lslCompDir.Strings[i] then begin
  2097.           result := false ;
  2098.           break ; //==>
  2099.         end ;
  2100.       end ;
  2101.     finally
  2102.       lslCompDir.free ;
  2103.     end ;
  2104.   finally
  2105.     lslCurrentDir.free ;
  2106.   end ;
  2107.  
  2108. end;
  2109. }
  2110. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2111. //*
  2112. //* File wide funcs and procs
  2113. //*
  2114. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2115. //------------------------------------------------------------------------------
  2116. function tiNumToken( sString, sToken : string ) : integer ;
  2117. var i, iCount : integer ;
  2118. begin
  2119.   iCount := 0 ;
  2120.   i := pos( sToken, sString ) ;
  2121.   while i <> 0 do begin
  2122.     delete( sString, i, length( sToken )) ;
  2123.     inc( iCount ) ;
  2124.     i := pos( sToken, sString ) ;
  2125.   end ;
  2126.   result := iCount + 1 ;
  2127. end ;
  2128.  
  2129. //------------------------------------------------------------------------------
  2130. function tiToken( sString, sToken : string; iNum : integer ) : string ;
  2131. var i, iCount, iNumToken : integer ;
  2132. begin
  2133.  
  2134.   result := '' ;
  2135.  
  2136.   iNumToken := tiNumToken( sString, sToken ) ;
  2137.   if iNum = 1 then begin
  2138.     if pos( sToken, sString ) = 0 then result := sString
  2139.     else result := copy( sString, 1, pos( sToken, sString )-1) ;
  2140.     end
  2141.   else if (iNumToken < iNum-1) or (iNum<1) then begin
  2142.     result := '' ;
  2143.     end
  2144.   else begin
  2145.  
  2146.     // Remove leading blocks
  2147.     iCount := 1 ;
  2148.     i := pos( sToken, sString ) ;
  2149.     while (i<>0) and (iCount<iNum) do begin
  2150.       delete( sString, 1, i ) ;
  2151.       inc( iCount ) ;
  2152.       i := pos( sToken, sString ) ;
  2153.     end ;
  2154.  
  2155.     if (i=0) and (iCount=iNum) then result := sString
  2156.     else if (i=0) and (iCount<>iNum) then result := ''
  2157.     else result := copy( sString, 1, i-length( sToken )) ;
  2158.  
  2159.   end ;
  2160. end ;
  2161.  
  2162. //------------------------------------------------------------------------------
  2163. function tiStrTran( sStr, sDel, sIns : string ) : string ;
  2164. var i : integer ;
  2165. begin
  2166.   i := pos( sDel, sStr ) ;
  2167.   while i <> 0 do begin
  2168.     delete( sStr, i, length( sDel )) ;
  2169.     insert( sIns, sStr, i ) ;
  2170.     i := pos( sDel, sStr ) ;
  2171.   end ;
  2172.   result := sStr ;
  2173. end ;
  2174.  
  2175. //------------------------------------------------------------------------------
  2176. function tiRemoveExtension( sValue : string ) : string ;
  2177. var i : integer ;
  2178. begin
  2179.   i := pos( '.', sValue ) ;
  2180.   if i <> 0 then begin
  2181.     result := copy( sValue, 1, i - 1 ) ;
  2182.   end else begin
  2183.     result := sValue ;
  2184.   end ;
  2185. end ;
  2186.  
  2187. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2188. //*
  2189. //* TnorFloatEdit ;
  2190. //*
  2191. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2192. //------------------------------------------------------------------------------
  2193. constructor TtiFloatEdit.create( owner : TComponent ) ;
  2194. begin
  2195.   inherited create( owner ) ;
  2196.   self.precision := 3 ;
  2197. end ;
  2198.  
  2199. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2200. //*
  2201. //* TnorCurrencyEdit ;
  2202. //*
  2203. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2204. //------------------------------------------------------------------------------
  2205. constructor TtiCurrencyEdit.create( owner : TComponent ) ;
  2206. begin
  2207.   inherited create( owner ) ;
  2208.   self.TextBefore := '$ ' ;
  2209.   self.precision := 2 ;
  2210. end ;
  2211.  
  2212. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2213. //*
  2214. //* TtiPercentEdit
  2215. //*
  2216. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2217. //------------------------------------------------------------------------------
  2218. constructor TtiPercentEdit.create( owner : TComponent ) ;
  2219. begin
  2220.   inherited create( owner ) ;
  2221.   self.textAfter  := ' %' ;
  2222.   self.precision := 0 ;
  2223. end ;
  2224.  
  2225. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2226. //*
  2227. //* TnorIntegerEdit
  2228. //*
  2229. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2230. //------------------------------------------------------------------------------
  2231. constructor TtiIntegerEdit.create( owner : TComponent ) ;
  2232. begin
  2233.   inherited create( owner ) ;
  2234. end ;
  2235.  
  2236. //------------------------------------------------------------------------------
  2237. function TtiIntegerEdit.getAsInteger : longInt ;
  2238. var r : real ;
  2239. begin
  2240. //  result := trunc( self.asFloat ) ;
  2241.   r := self.asFloat ;
  2242.   result := trunc( r ) + trunc( frac( r ) * 2 ) ;
  2243. end ;
  2244.  
  2245. //------------------------------------------------------------------------------
  2246. procedure TtiIntegerEdit.setAsInteger( iValue : longInt ) ;
  2247. begin
  2248.   self.asFloat := iValue ;
  2249. end ;
  2250.  
  2251. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2252. //*
  2253. //* TtiToolBar
  2254. //*
  2255. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2256. constructor TtiToolBar.create(owner: TComponent);
  2257. begin
  2258.   inherited create( owner ) ;
  2259.   self.flat   := true ;
  2260.   self.height := 25 ;
  2261. end;
  2262.  
  2263.  
  2264. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2265. //*
  2266. //* TtiPickAlias
  2267. //*
  2268. //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2269. procedure TtiPickAlias.ReadItems;
  2270. begin
  2271.   Items.Clear ;
  2272.   Session.GetAliasNames( Items ) ;
  2273. end;
  2274.  
  2275. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2276. // *
  2277. // * TtiDateRange
  2278. // *
  2279. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  2280. {------------------------------------------------------------------------------}
  2281. constructor TtiDateRange.create( oOwner : TComponent ) ;
  2282. begin
  2283.   inherited create( oOwner ) ;
  2284.  
  2285.   self.width  := 185 ;
  2286.   self.height := 113 ;
  2287.   self.caption := ' &Date range ' ;
  2288.  
  2289.   labelFrom := TLabel.create( self ) ;
  2290.   with labelFrom do begin
  2291.     parent  := self ;
  2292.     top     := 20 ;
  2293.     left    :=  8 ;
  2294.     caption := 'From' ;
  2295.   end ;
  2296.  
  2297.   labelTo := TLabel.create( self ) ;
  2298.   with labelTo do begin
  2299.     parent  := self ;
  2300.     top     :=  44  ;
  2301.     left    :=   8  ;
  2302.     caption := 'To' ;
  2303.   end ;
  2304.  
  2305.   FDateTimePickerFrom := TDateTimePicker.Create( self ) ;
  2306.   with FDateTimePickerFrom do begin
  2307.     parent   := self ;
  2308.     top      := 16 ;
  2309.     left     := 40 ;
  2310.     height   := 22 ;
  2311.     width    := 130 ;
  2312.     OnChange := OnChangeEvent ;
  2313.   end ;
  2314.  
  2315.   FDateTimePickerTo   := TDateTimePicker.Create( self ) ;
  2316.   with FDateTimePickerTo do begin
  2317.     parent   := self ;
  2318.     top      := 40 ;
  2319.     left     := 40 ;
  2320.     height   := 22 ;
  2321.     width    := 130 ;
  2322.     OnChange := OnChangeEvent ;
  2323.   end ;
  2324.  
  2325.   radioButtonDatesAll    := TRadioButton.create( self ) ;
  2326.   with radioButtonDatesAll do begin
  2327.     parent   := self ;
  2328.     top      := 70   ;
  2329.     left     :=  8   ;
  2330.     height   := 17   ;
  2331.     width    := 33   ;
  2332.     caption  := 'All' ;
  2333.     onClick  := radioButtonDatesClick ;
  2334.   end ;
  2335.  
  2336.   radioButtonDatesMonth  := TRadioButton.create( self ) ;
  2337.   with radioButtonDatesMonth do begin
  2338.     parent   := self ;
  2339.     height   := 17   ;
  2340.     left     :=  8   ;
  2341.     top      := 88   ;
  2342.     width    := 53   ;
  2343.     caption  := 'Month' ;
  2344.     onClick  := radioButtonDatesClick ;
  2345.   end ;
  2346.  
  2347.   radioButtonDatesWeek   := TRadioButton.create( self ) ;
  2348.   with radioButtonDatesWeek do begin
  2349.     parent   := self ;
  2350.     height   := 17   ;
  2351.     left     := 64   ;
  2352.     top      := 70   ;
  2353.     width    := 52   ;
  2354.     caption  := 'Week' ;
  2355.     onClick  := radioButtonDatesClick ;
  2356.   end ;
  2357.  
  2358.   radioButtonDatesToday  := TRadioButton.create( self ) ;
  2359.   with radioButtonDatesToday do begin
  2360.     parent   := self ;
  2361.     height   := 17   ;
  2362.     left     := 64   ;
  2363.     top      := 88   ;
  2364.     width    := 53   ;
  2365.     caption  := 'Today' ;
  2366.     onClick  := radioButtonDatesClick ;
  2367.   end ;
  2368.  
  2369.   radioButtonDatesCustom := TRadioButton.create( self ) ;
  2370.   with radioButtonDatesCustom do begin
  2371.     parent   := self ;
  2372.     height   := 17   ;
  2373.     left     := 120  ;
  2374.     top      := 70   ;
  2375.     width    := 61   ;
  2376.     caption  := 'Custom' ;
  2377.     onClick  := radioButtonDatesClick ;
  2378.   end ;
  2379.  
  2380. end ;
  2381.  
  2382.  
  2383. //------------------------------------------------------------------------------
  2384. procedure TtiDateRange.Loaded ;
  2385. begin
  2386.   inherited ;
  2387.   DateFrom := date ;
  2388.   DateTo   := date ;
  2389.   dateAllEarliest := encodeDate( 1, 1, 1 ) ;
  2390.   dateAllLatest   := encodeDate( 9999, 12, 31 ) ;
  2391.   radioButtonDatesCustom.Checked := true ;
  2392. end ;
  2393.  
  2394.  
  2395. {------------------------------------------------------------------------------}
  2396. procedure TtiDateRange.RadioButtonDatesClick(Sender: TObject);
  2397. var i      : integer ;
  2398.     wYear  : word ;
  2399.     wMonth : word ;
  2400.     wDay   : word ;
  2401. begin
  2402.  
  2403.   { Set the date maskEdit and speedButton enabled property as necessary. }
  2404.   FDateTimePickerFrom.enabled := radioButtonDatesCustom.checked ;
  2405.   FDateTimePickerTo.enabled   := radioButtonDatesCustom.checked ;
  2406.  
  2407.   decodeDate( date, wYear, wMonth, wDay ) ;
  2408.  
  2409.   for i := 0 to self.componentCount - 1 do begin
  2410.     if (self.components[i] is TRadioButton) then begin
  2411.       if TRadioButton(self.components[i]) <> TRadioButton( sender ) then begin
  2412.         TRadioButton( sender ).checked := true ;
  2413.       end ;
  2414.     end ;
  2415.   end ;
  2416.  
  2417.   if radioButtonDatesAll.checked then begin
  2418.     FDateTimePickerFrom.Date := dateAllEarliest ;
  2419.     FDateTimePickerTo.Date   := dateAllLatest ;
  2420.     FDateGroup := dgAll ;
  2421.     Exit ;
  2422.   end ;
  2423.  
  2424.   // Bug in set month after year was clicked.
  2425.   if radioButtonDatesMonth.checked then begin
  2426.     FDateTimePickerFrom.Date := encodeDate( wYear, wMonth, 1 ) ;
  2427.     if wMonth = 12 then begin
  2428.       wMonth := 1 ;
  2429.       inc( wYear ) ;
  2430.     end else begin
  2431.       inc( wMonth ) ;
  2432.     end ;
  2433.     FDateTimePickerTo.Date := encodeDate( wYear, wMonth, 1 ) - 1 ;
  2434.     FDateGroup := dgMonth ;
  2435.     Exit ;
  2436.   end ;
  2437.  
  2438.   if radioButtonDatesWeek.checked then begin
  2439.     FDateTimePickerFrom.Date := date - dayOfWeek( date ) + 1 ;
  2440.     FDateTimePickerTo.Date   := date - dayOfWeek( date ) + 7 ;
  2441.     FDateGroup := dgWeek ;
  2442.     Exit ;
  2443.   end ;
  2444.  
  2445.   if radioButtonDatesToday.checked then begin
  2446.     FDateTimePickerFrom.Date := date ;
  2447.     FDateTimePickerTo.Date   := date ;
  2448.     FDateGroup := dgToday ;
  2449.     Exit ;
  2450.   end ;
  2451.  
  2452.   { User entered date, do nothing }
  2453.   if radioButtonDatesCustom.checked then begin
  2454.     FDateGroup := dgCustom ;
  2455.   end ;
  2456.  
  2457.   OnChangeEvent( sender ) ;
  2458.  
  2459. end;
  2460.  
  2461. {------------------------------------------------------------------------------}
  2462. function  TtiDateRange.getDateFrom : TDateTime                 ;
  2463. begin
  2464.   result := trunc( FDateTimePickerFrom.Date ) ;
  2465. end ;
  2466.  
  2467. {------------------------------------------------------------------------------}
  2468. procedure TtiDateRange.putDateFrom( const dDate : TDateTime )        ;
  2469. begin
  2470.   FDateTimePickerFrom.Date := trunc( dDate ) ;
  2471. end ;
  2472.  
  2473. {------------------------------------------------------------------------------}
  2474. function TtiDateRange.getDateTo : TDateTime                   ;
  2475. begin
  2476.   result := trunc( FDateTimePickerTo.Date ) ;
  2477. end ;
  2478.  
  2479. {------------------------------------------------------------------------------}
  2480. procedure TtiDateRange.putDateTo( const dDate : TDateTime )          ;
  2481. begin
  2482.   FDateTimePickerTo.Date := trunc( dDate ) ;
  2483. end ;
  2484.  
  2485. {------------------------------------------------------------------------------}
  2486. {
  2487. function  TtiDateRange.getDateToAsString : string ;
  2488. begin
  2489.   result := tiDateTimeToStr( DateTo ) ;
  2490. end ;
  2491. }
  2492. {------------------------------------------------------------------------------}
  2493. {
  2494. procedure TtiDateRange.putDateToAsString( sDate : string )          ;
  2495. var dTemp : TDateTime ;
  2496. begin
  2497.   try
  2498.     dTemp := strToDateTime( sDate ) ;
  2499.     FDateTimePickerTo.Date := dTemp ;
  2500.   except
  2501.     messageDlg( sDate + ' is not a valid date',
  2502.                 mtError,
  2503.                 [mbOK],
  2504.                 0 ) ;
  2505.     FDateTimePickerTo.Date := date ;
  2506.   end ;
  2507. end ;
  2508. }
  2509.  
  2510. {------------------------------------------------------------------------------}
  2511. {
  2512. function  TtiDateRange.getDateFromAsString : string ;
  2513. begin
  2514.   Result := tiDateTimeToStr( FDateTimePickerFrom.Date ) ;
  2515. end ;
  2516. }
  2517.  
  2518. {------------------------------------------------------------------------------}
  2519. {
  2520. procedure TtiDateRange.putDateFromAsString( sDate : string )          ;
  2521. var dTemp : TDateTime ;
  2522. begin
  2523.   try
  2524.     dTemp := strToDateTime( sDate ) ;
  2525.     FDateTimePickerFrom.Date := dTemp ;
  2526.   except
  2527.     messageDlg( sDate + ' is not a valid date',
  2528.                 mtError,
  2529.                 [mbOK],
  2530.                 0 ) ;
  2531.     FDateTimePickerFrom.Date := date ;
  2532.   end ;
  2533. end ;
  2534. }
  2535.  
  2536. {------------------------------------------------------------------------------}
  2537. procedure TtiDateRange.setDateGroup( const dgDateGroup : TDateGroup ) ;
  2538. var radioButtonTemp : TRadioButton ;
  2539. begin
  2540.   FDateGroup := dgDateGroup ;
  2541.   case dgDateGroup of
  2542.     dgAll    : radioButtonTemp := radioButtonDatesAll    ;
  2543.     dgWeek   : radioButtonTemp := radioButtonDatesWeek   ;
  2544.     dgMonth  : radioButtonTemp := radioButtonDatesMonth  ;
  2545.     dgToday  : radioButtonTemp := radioButtonDatesToday  ;
  2546.     dgCustom : radioButtonTemp := radioButtonDatesCustom ;
  2547.   else
  2548.  
  2549.     radioButtonTemp := radioButtonDatesAll
  2550.   end ;
  2551.   with RadioButtonTemp do begin
  2552.     if showing then setFocus ;
  2553.     checked := true ;
  2554.   end ;
  2555. end ;
  2556.  
  2557.  
  2558. {------------------------------------------------------------------------------}
  2559. function TtiDateRange.getDateGroup : TDateGroup ;
  2560. begin
  2561.   result := FDateGroup ;
  2562.  
  2563. end ;
  2564.  
  2565. {------------------------------------------------------------------------------}
  2566. {
  2567. function TtiDateRange.geTtiDateRangeAsText : string ;
  2568. begin
  2569.   case self.DateGroup of
  2570.     dgAll    : result := 'All dates'    ;
  2571.     dgToday  : result := 'Date: ' + self.dateFromAsString  ;
  2572.   else
  2573.     result := 'From: ' +
  2574.               self.dateFromAsString +
  2575.               ' to ' +
  2576.               self.dateToAsString ;
  2577.   end ;
  2578. end ;
  2579. }
  2580.  
  2581. procedure TtiDateRange.OnChangeEvent(sender: TObject);
  2582. begin
  2583.   if not( sender is TRadioButton ) and ( FDateGroup <> dgCustom ) then exit ;
  2584.   if assigned( FOnChange ) then
  2585.     FOnChange( Sender ) ;
  2586. end;
  2587.  
  2588. procedure TBaseFloatEdit.BaseFloatEditClick( sender : TObject ) ;
  2589. begin
  2590.   SelectAll ;
  2591. end;
  2592.  
  2593. { TtiPanel }
  2594.  
  2595. constructor TtiPanel.Create(owner: TComponent);
  2596. begin
  2597.   inherited Create( owner ) ;
  2598.   ControlStyle := ControlStyle - [csSetCaption] ;
  2599.   BevelInner  := bvNone ;
  2600.   BevelOuter  := bvNone ;
  2601.   BorderStyle := bsNone ;
  2602. end;
  2603.  
  2604. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2605. // *
  2606. // * TtiClock
  2607. // *
  2608. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2609. constructor TtiClock.Create(owner: TComponent);
  2610. begin
  2611.   inherited Create( owner ) ;
  2612.   Parent         := owner as TWinControl ;
  2613.   FTimer         := TTimer.Create( self ) ;
  2614.   FLabel         := TLabel.Create( self ) ;
  2615.   FLabel.parent  := self ;
  2616.   FLabel.Top     := 2 ;
  2617.   FLabel.Left    := 2 ;
  2618.   FTimer.OnTimer := OnTimer ;
  2619.   FTimer.Enabled := false ;
  2620.   TimeFormat     := 'hh:mm:ss' ;
  2621.   FLabel.Caption := TimeFormat ;
  2622.   Offset         := 0 ;
  2623. end ;
  2624.  
  2625. //------------------------------------------------------------------------------
  2626. function TtiClock.GetEnabled: boolean;
  2627. begin
  2628.   result := FTimer.Enabled ;
  2629. end;
  2630.  
  2631. { ToDo 5 -cFramework: Make the TtiClock an observer so all instances of the clock share the same, global TTimer object. }
  2632. //------------------------------------------------------------------------------
  2633. procedure TtiClock.OnTimer( sender : TObject ) ;
  2634. begin
  2635.   try
  2636.     FLabel.Caption :=
  2637.       FormatDateTime( TimeFormat, Now + ( Offset * cdtOneSecond )) ;
  2638.   except
  2639.     on e:exception do begin
  2640.       Enabled := false ;
  2641.       MessageDlg( 'Error showing time. Message: ' + e.message ,
  2642.                   mtError, [mbOK], 0 ) ;
  2643.     end ;
  2644.   end ;
  2645. end ;
  2646.  
  2647. //------------------------------------------------------------------------------
  2648. procedure TtiClock.SetEnabled(Value: boolean);
  2649. begin
  2650.   FTimer.Enabled := Value ;
  2651.   if Enabled then
  2652.     OnTimer( nil ) ;
  2653. end;
  2654.  
  2655. //------------------------------------------------------------------------------
  2656. procedure TtiClock.SetTimeFormat(const Value: string);
  2657. begin
  2658.   FsTimeFormat := Value;
  2659.   ClientHeight   := Canvas.TextHeight( FsTimeFormat ) + 4 ;
  2660.   ClientWidth    := Canvas.TextWidth( FsTimeFormat ) + 4 ;
  2661. end;
  2662.  
  2663. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2664. // *
  2665. // * TtiButtonPanel
  2666. // *
  2667. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2668. { ToDo 5 -cComponents: TtiButtonPanel: Add variable number of buttons, with var captions and glyphs }
  2669. constructor TtiButtonPanel.Create(owner: TComponent);
  2670. begin
  2671.   inherited Create( owner ) ;
  2672.   Width  := 253 ;
  2673.   Height := 31  ;
  2674.   Align  := alBottom ;
  2675.   BevelOuter := bvNone ;
  2676.   ControlStyle := ControlStyle - [csSetCaption] ;
  2677.  
  2678.   FBtn1 := TBitBtn.Create( nil ) ;
  2679.   with FBtn1 do begin
  2680.     Parent   := self ;
  2681.     Left     := 94 ;
  2682.     Top      := 4  ;
  2683.     Width    := 75 ;
  2684.     Height   := 25 ;
  2685.     Anchors  := [akRight, akBottom] ;
  2686.     TabOrder := 0  ;
  2687.     OnClick  := DoBtn1Click ;
  2688.     Kind     := bkOK ;
  2689.     ModalResult := mrOK ;
  2690.   end ;
  2691.  
  2692.   FBtn2 := TBitBtn.Create( nil ) ;
  2693.   with FBtn2 do begin
  2694.     Parent   := self ;
  2695.     Left     := 174 ;
  2696.     Top      := 4 ;
  2697.     Width    := 75 ;
  2698.     Height   := 25 ;
  2699.     Anchors  := [akRight, akBottom] ;
  2700.     TabOrder := 1 ;
  2701.     OnClick  := DoBtn2Click ;
  2702.     Kind     := bkCancel ;
  2703.     ModalResult := mrCancel ;
  2704.   end ;
  2705. end ;
  2706.  
  2707. destructor TtiButtonPanel.Destroy;
  2708. begin
  2709.   FBtn1.Free ;
  2710.   FBtn2.Free ;
  2711.   inherited;
  2712. end;
  2713.  
  2714. procedure TtiButtonPanel.DoBtn1Click(sender: TObject);
  2715. begin
  2716.   if Assigned( FOnBtn1Click ) then
  2717.     FOnBtn1Click( self ) ;
  2718. end;
  2719.  
  2720. procedure TtiButtonPanel.DoBtn2Click(sender: TObject);
  2721. begin
  2722.   if Assigned( FOnBtn2Click ) then
  2723.     FOnBtn2Click( self ) ;
  2724. end;
  2725.  
  2726. procedure TtiButtonPanel.SetOnBtn1Click(const Value: TNotifyEvent);
  2727. begin
  2728.   FOnBtn1Click := Value;
  2729.   if Assigned( FOnBtn1Click ) then
  2730.     FBtn1.ModalResult := mrNone
  2731.   else
  2732.     FBtn1.ModalResult := mrOK ;
  2733. end;
  2734.  
  2735. procedure TtiButtonPanel.SetOnBtn2Click(const Value: TNotifyEvent);
  2736. begin
  2737.   FOnBtn2Click := Value;
  2738.   if Assigned( FOnBtn2Click ) then
  2739.     FBtn2.ModalResult := mrNone
  2740.   else
  2741.     FBtn2.ModalResult := mrCancel ;
  2742. end;
  2743.  
  2744. { TtiMessageDlg }
  2745.  
  2746. procedure TtiMessageDlg.Clear;
  2747. var
  2748.   i : integer ;
  2749. begin
  2750.   for i := 0 to FBtns.Count - 1 do
  2751.     TObject( FBtns.Items[i] ).Free ;
  2752. end;
  2753.  
  2754. constructor TtiMessageDlg.Create(owner: TComponent);
  2755. begin
  2756.   inherited Create( Owner ) ;
  2757.   FForm := TForm.Create( Nil ) ;
  2758.   FForm.Position := poScreenCenter ;
  2759.   FForm.Width := 320 ;
  2760.   FForm.Height := 250 ;
  2761.   FForm.BorderStyle := bsDialog ;
  2762.   FForm.BorderIcons := [] ;
  2763.   FForm.Visible := false ;
  2764.  
  2765.   FMemo := TMemo.Create( FForm ) ;
  2766.   FMemo.Parent := FForm ;
  2767.   FMemo.Top := 4 ;
  2768.   FMemo.Left := 4 ;
  2769.   FMemo.Width := 200 ;
  2770.   FMemo.Height := 150 ;
  2771.   FMemo.WordWrap := true ;
  2772.   FMemo.ScrollBars := ssNone ;
  2773.   FMemo.ReadOnly   := true ;
  2774.   FMemo.TabStop    := false ;
  2775.   FMemo.Color      := clBtnFace ;
  2776.   FMemo.BorderStyle := bsNone ;
  2777.  
  2778.   FBtns := TList.Create ;
  2779.  
  2780.   FsResult := '' ;
  2781.  
  2782. end;
  2783.  
  2784. destructor TtiMessageDlg.Destroy;
  2785. begin
  2786.   Clear ;
  2787.   FForm.Free ;
  2788.   FBtns.Free ;
  2789.   inherited;
  2790. end;
  2791.  
  2792.  
  2793. procedure TtiMessageDlg.DoOnClick(sender: TObject);
  2794. begin
  2795.   FsResult := TButton( Sender ).Caption ;
  2796.   FForm.ModalResult := mrOK ;
  2797. end;
  2798.  
  2799. function TtiMessageDlg.Execute( const psMessage: string;
  2800.                                 paOptions: array of string;
  2801.                                 psCaption : string ): string;
  2802. var
  2803.   lBtn : TButton ;
  2804.   i : integer ;
  2805. begin
  2806.   Clear ;
  2807.   FMemo.Lines.Text := psMessage ;
  2808.   for i := Low( paOptions ) to High ( paOptions ) do begin
  2809.     lBtn := TButton.Create( nil ) ;
  2810.     lBtn.Parent := FForm ;
  2811.     lBtn.Top := FMemo.Top + FMemo.Height + 4 ;
  2812.     lBtn.Left := 4 + ( lBtn.Width + 4 ) * i ;
  2813.     lBtn.Caption := paOptions[i] ;
  2814.     lBtn.OnClick := DoOnClick ;
  2815.     FBtns.Add( lBtn ) ;
  2816.   end ;
  2817.   FForm.Caption := psCaption ;
  2818.   FForm.ShowModal ;
  2819.   Result := FsResult ;
  2820. end;
  2821.  
  2822. end.
  2823.  
  2824.